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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking for the presense of a reg key

Status
Not open for further replies.

ErrolDC

MIS
May 26, 2004
72
US
How do I check for the presense of a registry key and gracefully exit if the key does not exist? Thsi is what I have so far and it throws an error instead of echo'ing the text I want.

dim SAV
set shell = CreateObject("Wscript.Shell")
SAV = shell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{948AC794-8B81-440A-81AE-6474337DB527}\Publisher")
if err.Number <> 0 then
Wscript.Echo "it's not installed"
else
Wscript.Echo "It's installed"
end if

Thanks in advance.
 
What is that code not doing that you want it to?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
well I want it to echo the text below. instead it says,

test2.vbs(3, 1) WshShell.RegRead: Invalid root in registry key "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{948AC794-8B81-440A-81AE-6474337DB527}\Publisher".

The whole idea is if the reg key is missing.. then so is the software which means it is not installed.

 
aaah...

Ttry this:
Code:
dim SAV
set shell = CreateObject("Wscript.Shell")
On Error Resume Next
SAV = shell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{948AC794-8B81-440A-81AE-6474337DB527}\Publisher")
if err.Number <> 0  then
Wscript.Echo "it's not installed"
else
Wscript.Echo "It's installed"
end if
On Error Goto 0

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Okay, so why did we need to specifiy those two lines?

 
Thanks ever so much.

If you don't mind, another question. Is there another way to check for the presense of a key without actually attempting to read something that may not exist?
 
I'm now trying to use RegObj.dll and I found quite a few examples that allow me to do what I want to do. I'm playing with it right now, but I must be doing something wrong because I can't get it to enumerate a list of registry subkeys. Here is what I have so far..

Code:
im SWKey, objRegRootKey, swname, ObjSubKey
set objReg = CreateObject("RegObj.Registry")
SWKey = "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
objRegRootKey = objReg.RegKeyFromString(SWKey)
        
        For Each objSubKey In objRegRootKey.SubKeys
                    Wscript.Echo " " &objSubKey.Name

        next

For some reason, when it gets to For statment, it bombs out with "...... runtime error: Object required: 'Uninstall".
I'm not sure why it's bombing out. I'm a newbie trying to learn vbscript so any kind of help would be appreciated.

 
ErrolDC,
[tt]
[red]set[/red] objRegRootKey = objReg.RegKeyFromString(SWKey)
[/tt]
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top