notta Posted June 5, 2007 Posted June 5, 2007 (edited) Guys I wrote a script a while back, but I'm having a brain fart right now. What I did before: for $k = 1 To $aRecords[0] Ping($new[$k],250) if @error Then; Could not even ping. Don't even waste time FileWriteLine("c:\results.txt", $new[$k] & "," & "could not ping") $noping = $noping + 1 Else $checkval1 = RegRead("\\" & $new[$k] & "\" & $key, "") if @error Then; Could not connect to registry. Must not have admin rights FileWriteLine("c:\results.txt", $new[$k] & "," & "Registry failure") $norights = $norights + 1 Else if $checkval == $regval Then; Remote Registry key matches required patched registry value FileWriteLine("c:\results.txt", $new[$k] & "," & "Completed") $patched = $patched + 1 Else FileWriteLine("c:\results.txt", $new[$k] & "," & "Not Patched") $notpatched = $notpatched + 1 EndIf EndIf EndIf Next This time I just want to find if a reg key exists and not a reg value. From what I can take you need to check for the default value of the key I'm looking for. Is that correct? I still want to keep the format where I ping the machine and if no reply than move onto the next. If I can ping I want to see if I have admin rights on the machine to even read the key. If I have admin rights I want to see if the key exists and if not than mark it as not existing so when I run the scan again later I can just scan the machines that still need a patch. Thanks. Oh yea, the thing that is making this more difficult for me is that I knew the key existed above, built in key for all Windows machine, but this key I don't know if it exists or not and this is what I'm checking for. If key does not exist than I need to patch the machine. Edited June 5, 2007 by notta
PsaltyDS Posted June 5, 2007 Posted June 5, 2007 You just want to loop RegEnumKey(): $ParentKey = "HKLM\SOFTWARE\Mozilla" $SearchKey = "Mozilla Firefox 2.0.0.4" $k = 1 While 1 If $SearchKey = RegEnumKey($ParentKey, $k) Then ExitLoop If @error Then $k = 0 ExitLoop EndIf WEnd If $k Then MsgBox(64, "Found Key", "Found reg key: " & $ParentKey & "\" & $SearchKey) Else MsgBox(16, "Key Not Found", "Did not find key: " & $ParentKey & "\" & $SearchKey) EndIf Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
notta Posted June 5, 2007 Author Posted June 5, 2007 Thanks for the help. I edited your code and changed the value of the $searchkey to equal my version of Firefox which is 2.0.0.3, but it failed. It would just sit there. My Mozilla Firefox 2.0.0.3 key is the 4th sub key in the Mozilla main key. I changed $k to 4 and it worked great. Is there anyway to search for the just the main key? Example HKLM\SOFTWARE\SOME PROGRAM. Thanks for the help Psalty. I may just have to search for a regvalue that is similiar in all installs of this software and than use regread. Funny thing is that I was testing regread: if RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\COM3", "") Then; key exists on my system MsgBox(0, "Test", "Exists") Else MsgBox(0, "Test", "Does not exist") EndIf This comes back as does not exist, so I guess regread is not meant to be used for this purpose even though the docs for regread states that if you want the default value than just use "". Thanks again Psalty.
PsaltyDS Posted June 5, 2007 Posted June 5, 2007 notta said: Thanks for the help. I edited your code and changed the value of the $searchkey to equal my version of Firefox which is 2.0.0.3, but it failed. It would just sit there. My Mozilla Firefox 2.0.0.3 key is the 4th sub key in the Mozilla main key. I changed $k to 4 and it worked great. Doh! I forgot to increment $k. Put that just before the WEnd in the While loop and it will work without having to know which key it is: $k = 1 While 1 If $SearchKey = RegEnumKey($ParentKey, $k) Then ExitLoop If @error Then $k = 0 ExitLoop EndIf $k += 1 WEnd Quote Is there anyway to search for the just the main key? Example HKLM\SOFTWARE\SOME PROGRAM. Thanks for the help Psalty.Just change the $ParentKey to "HKLM\SOFTWARE" and the $SearchKey to "Mozilla", or "Adobe", or whatever. Quote I may just have to search for a regvalue that is similiar in all installs of this software and than use regread. Funny thing is thatYou may be interested in a recursive registry search function posted by a certain devilishly good looking flightless waterfowl. Quote I was testing regread: if RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\COM3", "") Then; key exists on my system MsgBox(0, "Test", "Exists") Else MsgBox(0, "Test", "Does not exist") EndIf This comes back as does not exist, so I guess regread is not meant to be used for this purpose even though the docs for regread states that if you want the default value than just use "". Thanks again Psalty.RegRead() only reads 'Values', not 'Keys'. If the value name is "" then you are reading the 'Default' value. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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