Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

registry method to check if a key exists?

Status
Not open for further replies.

elmurado

IS-IT--Management
Jul 15, 2003
673
AU
Hi,
is there a method to check if a reg key exists?
Like FileExists but for reg keys?
If not, what kind of error output comes from running
objShell.RegDelete on a key that does not exist?

I need to check if a key exists in
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
ie in Add/Remove programs.
It is the curse of the dreaded symantec live update!
I need to get rid of it manually.
I can get rid of the folders with scripting ok and test that they're gone but don't know how to handle erros from reg methods.

thanks
 
ok, so I do things back to front-just checked the FAQ's-please feel free to flame my stupidity....
 
no, you need to try and read the key/value and trap for errors

strTemp = ""
Err.Clear
On Error Resume Next
strTemp = WshShell.RegRead(,,,)
On Error Goto 0
'either check
If Err.Number <> 0 Then ..... or If strTemp = "" Then

'the strTemp check might not be exactly what you want as the value could be blank but the key still exists,,,but i dont know your motives
 
Thanks mrmovie-that's what the function I got from the FAQ seems to do-something similar at least. It tries to read the reg key and then checks the error.
Yours seems a little more elegant.

I'm basically having to uninstall LiveUpdate manually because it won't go even when I use nonav. and I don't want to run through every machine in my domain to get rid of it.
Thanks
 
personally i dont like running methods which i think might cause a runtime. i think it is bad style. alternatively you would bind with WMI to the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall key then do an EnumKeys and look for the string/strings you are interested in.
if you are only looking for one string then it will be slower though...but lets say you are searching the a reg hive with loads of guids and you dont know which guid you want, you can EnumKeys then read the 'Description' value of each subkey to find the uninstall string of the product you are interested in....i digresss and have some exciting security patches to release.,.i hate fridays
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top