ViciousXUSMC Posted October 26, 2015 Posted October 26, 2015 (edited) So, stuck on a project.I want to try to edit a string located in the Stream_Autocomplete.dat file that Outlook uses for email address autocomplete. We are going to be moving an entire email server and so we want to change the old autocomplete entries.Instead of deleting the cache completely I was tasked to find a way to export, modify, and then import the data.My first step was finding all this data is stored in the above mentioned .dat file for Office 2010, and a .NK2 file for Office 2007 I have not even gotten to the NK2 file yet, but on this .dat I can open it up in Notepad++ and see its ANSI encoded and see the plain text strings I need to change.In Autoit however the _ReplaceStringInFile() does not work, and I have run through every FileOpen() FileRead() option I can think of and none of those have worked for me yet either.Wonder what I am doing wrong.Here is where I left off, its got a few testing things I have tried just so you get a feel for where I am at.expandcollapse popup#RequireAdmin #Include <Array.au3> #Include <File.au3> $sDirectory = @ScriptDir $aFiles = _FileListToArray($sDirectory, "Stream_Autocomplete*.dat", $FLTA_FILES, True) ;_ArrayDisplay($aFiles) For $i = 1 to $aFiles[0] $hFirst = FileOpen($aFiles[$i], 512) $sFile = FileRead($hFirst) FileClose($hFirst) $hFile = FileOpen($aFiles[$i], 514) $sFile2 = _ANSI2UNICODE($sFile) MsgBox(0, "", $sFile2) $sNewContent = StringRegExpReplace($sFile, "snip", "snip") $sNewContent2 = _UNICODE2ANSI($sNewContent) FileWrite($hFile, $sNewContent) FileClose($hFile) Next ;ou=Exchange Administrative Group (FYDIBOHF23SPDLT) Func _UNICODE2ANSI($sString = "") ; Convert UTF8 to ANSI to insert into DB ; http://www.autoitscript.com/forum/index.php?showtopic=85496&view=findpost&p=614497 ; ProgAndy ; Make ANSI-string representation out of UTF-8 Local Const $SF_ANSI = 1 Local Const $SF_UTF8 = 4 Return BinaryToString(StringToBinary($sString, $SF_UTF8), $SF_ANSI) EndFunc ;==>_UNICODE2ANSI Func _ANSI2UNICODE($sString = "") ; Extract ANSI and convert to UTF8 to display ; http://www.autoitscript.com/forum/index.php?showtopic=85496&view=findpost&p=614497 ; ProgAndy ; convert ANSI-UTF8 representation to ANSI/Unicode Local Const $SF_ANSI = 1 Local Const $SF_UTF8 = 4 Return BinaryToString(StringToBinary($sString, $SF_ANSI), $SF_UTF8) EndFunc ;==>_ANSI2UNICODE Edited October 27, 2015 by ViciousXUSMC
water Posted October 26, 2015 Posted October 26, 2015 Maybe this tool does what you need: http://www.nirsoft.net/utils/outlook_nk2_edit.html My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
ViciousXUSMC Posted October 27, 2015 Author Posted October 27, 2015 Yes it does, work in progress. I need to add more checks to determine x86 x64, Outlook 2007/2010/2013 and diversify how 2007 uses NK2 and 2010 uses .Dat but its a proof of concept and working on my computer. NK2 Edit can actually do the string changes itself, but I felt it was easier for me to use AutoIT.#RequireAdmin #Include <Array.au3> #Include <File.au3> FileInstall("NK2Edit.exe", @TempDir & "\NK2Edit.exe", 1) $sDirectory = @ScriptDir ;Directory of .NK2 or .Dat File $aFiles = _FileListToArray($sDirectory, "Stream_Autocomplete*.dat", $FLTA_FILES, True) ;Put List of Files in Array Local $aFilesDate[$aFiles[0]+1][2] ;Declare New Array with Extra Colum to add Modified Date For $i = 0 to $aFiles[0] $aFilesDate[$i][0] = $aFiles[$i] ;Copy First Array Column To New Array $aFilesDate[$i][1] = FileGetTime($aFiles[$i], 0, 1) ;Add Last Modified Date To Second Column in New Array Next $iRowCount = $aFilesDate[0][0] ;Index Count from Array to use as Row Count before Sort _ArraySort($aFilesDate, 0, 0, 0, 1) ;Sort New Array So the Most Recent Modified File is Listed Last _ArrayDisplay($aFilesDate) ;Show Current Array $sAutoCompleteFile = $aFilesDate[$iRowCount][0] ;Most Recent File will be $aFilesDate[$iRowCount] FileCopy($sAutoCompleteFile, @TempDir & "\TempAutoComplete.dat", 1) FileCopy($sAutoCompleteFile, $sAutoCompleteFile & ".bak", 1) Run(@ComSpec & " /k " & @TempDir & "\NK2Edit.exe /nk2_to_text " & @TempDir & "\TempAutoComplete.dat" & " " & @TempDir & "\TempAutoComplete.txt", @ScriptDir, @SW_HIDE) Sleep(2000) _ReplaceStringInFile(@TempDir & "\TempAutoComplete.txt", "@polkfl.com", "@polk-county.net") Run(@ComSpec & " /k " & @TempDir & "\NK2Edit.exe /text_to_nk2 " & @TempDir & "\TempAutoComplete.txt" & " " & @TempDir & "\TempAutoComplete.nk2", @ScriptDir, @SW_HIDE) FileCopy(@TempDir & "\TempAutoComplete.nk2", "C:\Users\" & @UserName & "\AppData\Local\Microsoft\Outlook\Outlook.nk2", 1) Run("C:\Program Files (x86)\Microsoft Office\Office14\Outlook.exe /importnk2", @ScriptDir, @SW_HIDE)So I still have a long way to go on this one, also I need to name the NK2 file the users email profile name, so I need a way to get that not sure if registry or perhaps your Outlook.UDF
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now