GEOSoft Posted March 26, 2009 Share Posted March 26, 2009 (edited) You can use either the abbreviated or full key names (HKLM64 or HKEY_LOCAL_MACHINE64) Example Usage ; $sKey = "HKLM\SYSTEM\CurrentControlSet\Control" _OpenRegEdit($sKey) ; Functions expandcollapse popup; Func _OpenRegEdit($sKey) Local $sUser, $sReg, $sProc = "regedit.exe" $sKey = StringReplace($sKey,"HKU", "HKey_USERS") $sKey = StringReplace($sKey, "HKLM", "HKEY_LOCAL_MACHINE") $sKey = StringReplace($sKey, "HKCU", "HKEY_CURRENT_USER") $sKey = StringReplace($sKey, "HKCR", "HKEY_CLASSES_ROOT") $sKey = StringReplace($sKey, "HKCC", "HKEY_CURRENT_CONFIG") RegRead($sKey, "") If NOT StringRegExp(@Error, "-1|0") Then Return SetError(@Error) $sKey = "My Computer\" & $sKey $sUser = _UserID() If $sUser Then $sReg = "HKU\" & $sUser & "\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit" If RegWrite($sReg, "LastKey", "Reg_SZ", $sKey) Then If ProcessExists($sProc) Then ProcessClose($sProc) ShellExecute($sProc) Return True EndIf EndIf Return False EndFunc ;<==> _OpenRegEdit() Func _UserID() Local $sKey = "HKCU\Software\Microsoft\Protected Storage System Provider\" Local $sEntry, $iReg = 1, $sRegEx = "(?i)(s-1-5-21-[\d|-]*)" While 1 $sEntry = RegEnumKey($sKey, $iReg) If @Error Then ExitLoop $iReg += 1 If NOT StringRegExp($sEntry, $sRegEx) Then ContinueLoop Local $aRegExp = StringRegExp($sEntry, $sRegEx, 1) Return $aRegExp[0] Wend Return False EndFunc ;<==> _UserID() ; Edited March 28, 2009 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
WideBoyDixon Posted March 26, 2009 Share Posted March 26, 2009 Ermm .... Func _OpenRegEdit($sKey) Local $sProc = "regedit.exe" $sKey = StringReplace($sKey,"HKU", "HKEY_USERS") $sKey = StringReplace($sKey, "HKLM", "HKEY_LOCAL_MACHINE") $sKey = StringReplace($sKey, "HKCU", "HKEY_CURRENT_USER") $sKey = StringReplace($sKey, "HKCR", "HKEY_CLASSES_ROOT") $sKey = StringReplace($sKey, "HKCC", "HKEY_CURRENT_CONFIG") RegRead($sKey, "") If @Error < -1 OR @Error > 0 Then Return SetError(@Error) $sKey = "My Computer\" & $sKey If RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit", "LastKey", "Reg_SZ", $sKey) Then If ProcessExists($sProc) Then ProcessClose($sProc) ShellExecute($sProc) Return True EndIf EndFunc ;<==> _OpenRegEdit() Surely drilling down in to HKEY_USERS with the right UserID is the same as going to HKEY_CURRENT_USER? WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
WideBoyDixon Posted March 26, 2009 Share Posted March 26, 2009 Another thought ... perhaps it's avoidable to close the process ... expandcollapse popupFunc _OpenRegEdit($sKey) Local $sProc = "regedit.exe" $sKey = StringReplace($sKey,"HKU", "HKEY_USERS") $sKey = StringReplace($sKey, "HKLM", "HKEY_LOCAL_MACHINE") $sKey = StringReplace($sKey, "HKCU", "HKEY_CURRENT_USER") $sKey = StringReplace($sKey, "HKCR", "HKEY_CLASSES_ROOT") $sKey = StringReplace($sKey, "HKCC", "HKEY_CURRENT_CONFIG") RegRead($sKey, "") If @Error < -1 OR @Error > 0 Then Return SetError(@Error) If ProcessExists($sProc) Then _NavigateToKey($sKey) Return True Else $sKey = "My Computer\" & $sKey If RegWrite("HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit", "LastKey", "Reg_SZ", $sKey) Then ShellExecute($sProc) Return True EndIf EndIf EndFunc ;<==> _OpenRegEdit() Func _NavigateToKey($sKey) Local $i WinActivate("Registry Editor") ControlFocus("Registry Editor", "", "[CLASS:SysTreeView32; INSTANCE:1]") For $i = 1 To 30 Send("{LEFT}") Next Send("{RIGHT}") For $i = 1 To StringLen($sKey) If StringMid($sKey, $i, 1) = "\" Then Send("{RIGHT}") Else Send(StringMid($sKey, $i, 1)) EndIf Sleep(10) Next EndFunc WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
GEOSoft Posted March 26, 2009 Author Share Posted March 26, 2009 For your first reply. We need to write to the key in HKU which we could go directly to if there was only one user. If there are more than one user then we have to get the ID of the current user and go to that hive in HKU. For your second reply. You could do that but I found it was fast enough to close and reopen. The odds are that you won't have regedit already open at that point anyway and close/reopen makes sure that everything is refreshed. Thanks George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
WideBoyDixon Posted March 26, 2009 Share Posted March 26, 2009 (edited) [1] Perhaps it's a Vista thing (I'm still on XP). I always thought HKEY_CURRENT_USER points to exactly the same hive as HKEY_USERS\{SID of current user} but I'm happy to be wrong (it's not the first time). [2] Absolutely. I was just posting an "example script" for another method and cheekily tagging it on to your post I bow to the MVP ... WBD Edited March 26, 2009 by WideBoyDixon [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
GEOSoft Posted March 26, 2009 Author Share Posted March 26, 2009 [1] Perhaps it's a Vista thing (I'm still on XP). I always thought HKEY_CURRENT_USER points to exactly the same hive as HKEY_USERS\{SID of current user} but I'm happy to be wrong (it's not the first time). WBDI don't use Vista, XP and Win 7. What you say is correct for most of the keys inside those 2 hives however the key that I need to write to is not one of them. It has to be done in HKU. No Bowing allowed. I wouldn't mind but we don't have video on the forums so I wouldn't get to enjoy it. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Valuater Posted March 26, 2009 Share Posted March 26, 2009 Maybe... If @Error <= -1 OR @Error > 0 Then Return SetError(@Error)oÝ÷ ØêÚºÚ"µÍÌÍÜÔYÈHYÔXY ÌÍÜÒÙ^K ][ÝÉ][ÝÊBY ÌÍÜÔYÈH ][ÝÉ][ÝÈ[]Ù]ÜÜ 8) Link to comment Share on other sites More sharing options...
GEOSoft Posted March 26, 2009 Author Share Posted March 26, 2009 Maybe... If @Error <= -1 OR @Error > 0 Then Return SetError(@Error)oÝ÷ ØêÚºÚ"µÍÌÍÜÔYÈHYÔXY ÌÍÜÒÙ^K ][ÝÉ][ÝÊBY ÌÍÜÔYÈH ][ÝÉ][ÝÈ[]Ù]ÜÜ 8)Damn AutoIt Tags. Can't do that because if you read the default and there is no value set it will return -1 as the error even though the key is indeed valid and does exist. That's the same reason you can't simply use If @Error Then ...... I had to recently fix the same thing in someone elses version of a KeyExists() function. I could ignore the -2 code as I recall but for the extra time it takes to type the line it might as well stay there. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
bo8ster Posted March 26, 2009 Share Posted March 26, 2009 I don't use Vista, XP and Win 7. What you say is correct for most of the keys inside those 2 hives however the key that I need to write to is not one of them. It has to be done in HKU.No Bowing allowed. I wouldn't mind but we don't have video on the forums so I wouldn't get to enjoy it.Just curious GEOSoft, what OS do you use? Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
GEOSoft Posted March 27, 2009 Author Share Posted March 27, 2009 I worded that wrong. I use XP SP3 and Win 7 George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
GEOSoft Posted March 28, 2009 Author Share Posted March 28, 2009 Maybe... If @Error <= -1 OR @Error > 0 Then Return SetError(@Error) 8)You gave me an idea for that line so I've changed it. If NOT StringRegExp(@Error, "-1|0") Then Return SetError(@Error) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
WideBoyDixon Posted March 28, 2009 Share Posted March 28, 2009 (edited) Just for fun ... If Abs(@Error + 0.5) <> 0.5 Then Return SetError(@Error) WBD Edited March 28, 2009 by WideBoyDixon [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] 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