Doppio Posted January 19, 2006 Share Posted January 19, 2006 Hi, I'm using the following code to backup the current user Outlook registry settings runwait(@comspec & " /c " & 'REGEDIT /E ' & 'H:\Outlook.reg "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"', "" ,@SW_HIDE) My question is; if more than 2 people use Outlook under different accounts, how can I backup their Outlook registry settings, without login into each user account? Thank you. Link to comment Share on other sites More sharing options...
rudika Posted January 19, 2006 Share Posted January 19, 2006 (edited) Hi, I'm using the following code to backup the current user Outlook registry settings runwait(@comspec & " /c " & 'REGEDIT /E ' & 'H:\Outlook.reg "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"', "" ,@SW_HIDE) My question is; if more than 2 people use Outlook under different accounts, how can I backup their Outlook registry settings, without login into each user account? Thank you. Hi, I think the best way is the startup folder for everyone. If you build a quary that check fist the current settings and run the script if it has to be change. Edited January 19, 2006 by rudika [font="Comic Sans Ms"][center]Powered by AutoIt3http://www.wik-eric.de/zips/Synchro2.2.2-4free.zip[/center][/font] Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted January 19, 2006 Moderators Share Posted January 19, 2006 Could you not replace HKCU with HKU? Then do a For...Next for all the subkeys under HKU. Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted January 19, 2006 Moderators Share Posted January 19, 2006 (edited) It been a quiet morning so I thought I'd whip this up for you: #include <RegCount.au3> #include <Array.au3> Dim $Key = "HKEY_Users" Dim $TotalKeys = _RegKeyCount ($Key) Dim $List[$TotalKeys] For $i = 1 To $TotalKeys $var = RegEnumKey($Key, $i) If @error <> 0 Then ExitLoop $List[$i - 1] = RegRead($Key & "\" & $var & "\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles", "DefaultProfile") If $List[$i - 1] = "" Then ContinueLoop RunWait(@ComSpec & " /c " & 'REGEDIT /E ' & 'H:\Outlook_' & $var & '.reg ' & '"' & $Key & "\" & $var & '\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"', "", @SW_SHOW) Next Edited January 19, 2006 by big_daddy Link to comment Share on other sites More sharing options...
Doppio Posted January 19, 2006 Author Share Posted January 19, 2006 It been a quiet morning so I thought I'd whip this up for you: #include <RegCount.au3> #include <Array.au3> Dim $Key = "HKEY_Users" Dim $TotalKeys = _RegKeyCount ($Key) Dim $List[$TotalKeys] For $i = 1 To $TotalKeys $var = RegEnumKey($Key, $i) If @error <> 0 Then ExitLoop $List[$i - 1] = RegRead($Key & "\" & $var & "\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles", "DefaultProfile") If $List[$i - 1] = "" Then ContinueLoop RunWait(@ComSpec & " /c " & 'REGEDIT /E ' & 'H:\Outlook_' & $var & '.reg ' & '"' & $Key & "\" & $var & '\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"', "", @SW_SHOW) Next Great! now I'm able to retrieve all the Outlook settings from all the local users. Just One more question if you have time.. How would I know which key belongs to which user? Is there a way to translate, or maybe have the output come out with the User's name Outlook_Jhon.reg Thank you for your prompt reply. Link to comment Share on other sites More sharing options...
CyberSlug Posted January 19, 2006 Share Posted January 19, 2006 (edited) You might be able to decode some of the registry keys. Here's an example from my registry (XP Pro with Outlook 2003) $bin = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\9375CFF0413111d3B88A00104B2A6676\00000002", "Account Name") ; In my case, $bin is ; 4D006900630072006F0073006F00660074002000450078006300680061006E00670065002000530065007200760065007200 0000 MsgBox(4096,"Example", reghex2txt($bin)) Exit Func reghex2txt($input) Local $result = "", $char = "" For $i = 1 to StringLen($input) Step 2 $char = StringMid($input, $i, 2) If $char <> "00" Then $result = $result & Chr( Dec(($char)) ) Next Return $result EndFunc Edit: The message box prints "Microsoft Exchange Server" in my case. Edited January 19, 2006 by CyberSlug Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted January 19, 2006 Moderators Share Posted January 19, 2006 Great! now I'm able to retrieve all the Outlook settings from all the local users. Just One more question if you have time.. How would I know which key belongs to which user? Is there a way to translate, or maybe have the output come out with the User's name Outlook_Jhon.reg Thank you for your prompt reply. Yeah that shouldn't be too hard give me a few minutes. Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted January 19, 2006 Moderators Share Posted January 19, 2006 (edited) Well it ended up being harder than I had thought, but this should work. You will need to specify what version of office they have installed for it to work correctly (see comment). #include <RegCount.au3> #include <Array.au3> #include <String.au3> Dim $Key = "HKEY_Users" Dim $OfficeVer = "10.0"; Office 2003 = 11.0, Office XP = 10.0, Office 2000 SP3 = 9.0 Dim $TotalKeys = _RegKeyCount ($Key) Dim $List[$TotalKeys] Dim $HexName[$TotalKeys] For $i = 1 To $TotalKeys $var = RegEnumKey($Key, $i) If @error <> 0 Then ExitLoop $List[$i - 1] = RegRead($Key & "\" & $var & "\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles", "DefaultProfile") If $List[$i - 1] = "" Then ContinueLoop $HexName[$i - 1] = RegRead($Key & "\" & $var & "\Software\Microsoft\Office\" & $OfficeVer & "\Common\UserInfo", "UserName") $UserName = StringStripWS(_HexToString (StringReplace($HexName[$i - 1], "00", "")), 8) RunWait(@ComSpec & " /c " & 'REGEDIT /E ' & 'H:\Outlook_' & $UserName & '.reg ' & '"' & $Key & "\" & $var & '\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"', "", @SW_HIDE) Next Edited January 19, 2006 by big_daddy Link to comment Share on other sites More sharing options...
Doppio Posted January 19, 2006 Author Share Posted January 19, 2006 It been a quiet morning so I thought I'd whip this up for you: #include <RegCount.au3> #include <Array.au3> Dim $Key = "HKEY_Users" Dim $TotalKeys = _RegKeyCount ($Key) Dim $List[$TotalKeys] For $i = 1 To $TotalKeys $var = RegEnumKey($Key, $i) If @error <> 0 Then ExitLoop $List[$i - 1] = RegRead($Key & "\" & $var & "\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles", "DefaultProfile") If $List[$i - 1] = "" Then ContinueLoop RunWait(@ComSpec & " /c " & 'REGEDIT /E ' & 'H:\Outlook_' & $var & '.reg ' & '"' & $Key & "\" & $var & '\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"', "", @SW_SHOW) Next When I run your script I get the following Outlook_S-1-5-21-1454471165-602162358-725345543-1005.reg Outlook_S-1-5-21-1454471165-602162358-725345543-1012.reg Each key belongs to the two users that log on the PC, which is great. On your Second reply I get the Key with the Registered Microsoft Username, not the Windows Username. Outlook_Walter.reg What I wanted to know is which Key belongs to which User? The two users are Tom, and Jack Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted January 19, 2006 Moderators Share Posted January 19, 2006 Well if someone can convert this script it will change the SID to the Username FetchUserName: This function is used to get the object name and the domain name, provided the SID and the system name is available. In case the system name is not available, it will be assumed that the SID on the local machine is to be obtained. The system name can be a domain wide name and could be in the format Domainname\SystemName. FetchUserName(LPTSTR strtext,LPTSTR lpSystemName, LPTSTR *lpUserName, LPTSTR *lpDomainName){ Sid = GetBinarySid(strtext); //convert stringSID to SID structure RetBln = LookupAccountSid(lpSystemName, Sid, *lpUserName, &usernameLength, *lpDomainName, &domainnameLength, &snu); //function used to get the name //of the object given the SID structure is given } Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted January 19, 2006 Moderators Share Posted January 19, 2006 You could use this command line tool to convert them. Maybe someone else can tell you how to pull the returned username from the cmd window.SidToName Link to comment Share on other sites More sharing options...
Doppio Posted January 19, 2006 Author Share Posted January 19, 2006 You could use this command line tool to convert them. Maybe someone else can tell you how to pull the returned username from the cmd window.SidToNameThank you for your great insights. I'll follow your advice. Link to comment Share on other sites More sharing options...
Doppio Posted January 19, 2006 Author Share Posted January 19, 2006 You could use this command line tool to convert them. Maybe someone else can tell you how to pull the returned username from the cmd window. SidToName I got this from Danny35d. Can you help me put everything toogether? expandcollapse popup#include <GUIConstants.au3> #include <GuiCombo.au3> Dim $SID $SID = _UserSID(); Create an array with all username from the local machine ;$SID = _UserSID(@UserName); Create an array with only the specific username from the local machine ;$SID = _UserSID('', @ComputerName); Create an array with all username from the remote machine ;$SID = _UserSID(@UserName, @ComputerName); Create an array with only the specific username from the remote machine ; == GUI generated with Koda == $Form1 = GUICreate("AForm1", 622, 441, 192, 125) $Label1 = GUICtrlCreateLabel('Select User', 208, 160) $Combo1 = GUICtrlCreateCombo("", 208, 176, 153, 21) $Button1 = GUICtrlCreateButton('Find SID', 250, 200) ;Adding username to combobox For $x = 1 To $SID[0][0] _GUICtrlComboAddString($Combo1, $SID[0][$x]) Next GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button1;Searching for the SID For $x = 1 To $SID[0][0] $User = GUICtrlRead($Combo1) If $User == $SID[0][$x] Then MsgBox(0, 'SID', 'User SID is' & @CRLF & @CRLF & $SID[1][$x]) ExitLoop EndIf Next Case Else ;;;;;;; EndSelect WEnd Exit ;=============================================================================== ; Function Name: _UserSID() ; ; Description: Return a 2 dimensional array first username second SID. ; ; Syntax: _UserSID ( [$s_UserName, $s_RemoteComputer] ) ; ; Parameter(s): $s_UserName = Username to get SID. ; $s_RemoteComputer = ComputerName on the network ; ; Requirement(s): External: = None. ; Internal: = None. ; ; Return Value(s): On Success: = Returns 2 dimensional array with UserName, SID and sets @error to 0. ; On Failure: = Returns "" and sets @error to 1. ; ; Author(s): Dan Colón ; ; Note(s): ; ; Example(s): ; _UserSID("DColon") it will return DColon SID ; _UserSID() it will return every user SID ;=============================================================================== Func _UserSID($s_UserName = "All", $s_RemoteComputer = '') If $s_UserName = '' Then $s_UserName = 'All' If $s_RemoteComputer <> '' Then If StringMid($s_RemoteComputer, 1, 1) <> '\' Or StringMid($s_RemoteComputer, 2, 1) <> '\' Or StringRight($s_RemoteComputer, 1) <> '\' Then $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\' EndIf EndIf Local $line, $var, $ProfilePath, $i = 1 Local Const $regkey = $s_RemoteComputer & "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" Local Const $regkeyval1 = "ProfilesDirectory" Local Const $regkeyval2 = "ProfileImagePath" $ProfilePath = RegRead($regkey, $regkeyval1) While 1 $line = RegEnumKey($regkey, $i) $var = RegRead($regkey & $line, $regkeyval2) If @error = 1 Or @error = -1 Then ExitLoop If $s_UserName == "All" Then If Not IsDeclared("aArray") Then Dim $aArray[1][1] ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1] $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1) $aArray[1][UBound($aArray) - 1] = $line $aArray[0][0] = UBound($aArray) - 1 ElseIf StringLower($var) == StringLower($ProfilePath & "\" & $s_UserName) Then If Not IsDeclared("aArray") Then Dim $aArray[1][1] ReDim $aArray[UBound($aArray) + 1][UBound($aArray) + 1] $aArray[0][UBound($aArray) - 1] = StringMid($var, StringInStr($var, '\', 0, -1) + 1) $aArray[1][UBound($aArray) - 1] = $line $aArray[0][0] = UBound($aArray) - 1 EndIf $i = $i + 1 WEnd If Not IsDeclared("aArray") Then SetError(1) Return ("") Else SetError(0) Return ($aArray) EndIf EndFunc ;==>_UserSID Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted January 20, 2006 Moderators Share Posted January 20, 2006 I'm at home so I can't test it, but I think this will work. #include <RegCount.au3> #include <Array.au3> #include <String.au3> Dim $Key = "HKEY_Users" Dim $TotalKeys = _RegKeyCount ($Key) Dim $List[$TotalKeys] Dim $ProfilePath[$TotalKeys] For $i = 1 To $TotalKeys $var = RegEnumKey($Key, $i) If @error <> 0 Then ExitLoop $List[$i - 1] = RegRead($Key & "\" & $var & "\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles", "DefaultProfile") If $List[$i - 1] = "" Then ContinueLoop $ProfilePath[$i - 1] = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\' & $var, "ProfileImagePath") $UserName = StringMid($ProfilePath[$i - 1], StringInStr($ProfilePath[$i - 1], '\', 0, -1) + 1) RunWait(@ComSpec & " /c " & 'REGEDIT /E ' & '"H:\Outlook_' & $UserName & '.reg" ' & '"' & $Key & "\" & $var & '\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"', "", @SW_HIDE) Next Link to comment Share on other sites More sharing options...
Doppio Posted January 20, 2006 Author Share Posted January 20, 2006 I'm at home so I can't test it, but I think this will work. #include <RegCount.au3> #include <Array.au3> #include <String.au3> Dim $Key = "HKEY_Users" Dim $TotalKeys = _RegKeyCount ($Key) Dim $List[$TotalKeys] Dim $ProfilePath[$TotalKeys] For $i = 1 To $TotalKeys $var = RegEnumKey($Key, $i) If @error <> 0 Then ExitLoop $List[$i - 1] = RegRead($Key & "\" & $var & "\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles", "DefaultProfile") If $List[$i - 1] = "" Then ContinueLoop $ProfilePath[$i - 1] = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\' & $var, "ProfileImagePath") $UserName = StringMid($ProfilePath[$i - 1], StringInStr($ProfilePath[$i - 1], '\', 0, -1) + 1) RunWait(@ComSpec & " /c " & 'REGEDIT /E ' & '"H:\Outlook_' & $UserName & '.reg" ' & '"' & $Key & "\" & $var & '\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"', "", @SW_HIDE) Next Great Job! This forum rocks. I like the way programmers like you help us the new guys with any type of question. Thank you. Here's my little script to backup outlook profiles. Thanks to Danny35d for his help in getting the User's SID Outlook_Backup.au3 Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted January 20, 2006 Moderators Share Posted January 20, 2006 (edited) Glad I was able to help! I added a restore function to your script.Outlook_Backup.au3Edit1: Added a silent switch for the restore.Edit2: Added a MsgBox if the restore file doesn't exist. Edited January 20, 2006 by big_daddy Link to comment Share on other sites More sharing options...
Doppio Posted January 20, 2006 Author Share Posted January 20, 2006 Glad I was able to help! I added a restore function to your script. Edit: Added a silent switch for the restore. Thank you, you red my mind, I tried backing up and restoring different test accounts and workded great, but there was one Profile that gave me the following error Cannot Import c:\Outlook.reg Error accessing the registry I'm running the script as a local Administrator. Is there a limitation on the size of the Reg key that you can restore? Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted January 20, 2006 Moderators Share Posted January 20, 2006 Cannot Import c:\Outlook.reg Error accessing the registry Did you remove the username or was it never there? If it was never there then the file probably didn't exist, I added a FileExists() to the script posted above. Is there a limitation on the size of the Reg key that you can restore?No, you should be able to restore the whole registry without any problem. Link to comment Share on other sites More sharing options...
Doppio Posted January 20, 2006 Author Share Posted January 20, 2006 Cannot Import c:\Outlook.reg Error accessing the registry Did you remove the username or was it never there? If it was never there then the file probably didn't exist, I added a FileExists() to the script posted above. No, you should be able to restore the whole registry without any problem. I created 3 different Usernames, logedin and configured Outlook with different settings for each user (Calendar, Contacts, etc..) then I loged in as the local Administrator, backed up each user's Outlook.reg key. I restored User#1, User#2, but on User#3 It failed with the previous error. Any Ideas? Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted January 20, 2006 Moderators Share Posted January 20, 2006 I created 3 different Usernames, logedin and configured Outlook with different settings for each user (Calendar, Contacts, etc..) then I loged in as the local Administrator, backed up each user's Outlook.reg key. I restored User#1, User#2, but on User#3 It failed with the previous error. Any Ideas? That's why I asked if the filename was just "Outlook.reg". Go to your c drive and check the filenames, you should have: Outlook_User#1.reg, Outlook_User#2.reg, Outlook_User#3.reg If one of them is just Outlook.reg or there is one missing then something went wrong with the backup. Let me know what you find. p.s. download this file again to make sure you have the one with the FileExists() Outlook_Backup.au3 Link to comment Share on other sites More sharing options...
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