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!

How to read if a registry "KEY" exists

Status
Not open for further replies.

KRPGroup

MIS
Jun 22, 2005
317
CA
I have code that will find the Value or Data but NOT just a Key itself.

I have a program that only has the (Default) value in the registry, which my code will not find? I want to use it to confirm if it is installed and then remove it if it is but I need to check for this reg Key.

This is just a fragment of the full code for testing. The reg key I'm looking for is as follows
[HKEY_LOCAL_MACHINE\SOFTWARE\CaseWare International\CaseWare Connector\2005.00.000]
Code:
On Error Resume Next
 
Dim Cw2005,Cwc2005,Cw2006,Cwc2006,CwInstall,CwcInstall,etc...
 
Set WshShell=CreateObject("WScript.Shell")
scomputername = createobject("wscript.network").computername 

Cwc2005 = "HKEY_LOCAL_MACHINE\SOFTWARE\CaseWare International\CaseWare Connector\2005.00.000[COLOR=red][b]\[/b][/color]"

'---Reading registry to see if CW2005 Connector is installed 
    err.clear

    WSHShell.RegRead(Cwc2005)
     
    If Err Then
            'Already been run, exit IF
            WScript.Echo "CaseWare Connector 2005 Program not found" '---For Testing Only
    
    Else
            '---Removing CwConnector2005
            WScript.Echo "CaseWare Connector 2005 found, Un-install required" '---For Testing Only
            WSHShell.Run exeCwcUninstall, , True

    End If


Set WSHSHell = Nothing
WScript.Quit


I tried with and without a "\" at the end of the string and when it runs it is still returning an error. I thought maybe I have it backwards so for testing I deleted the "CaseWare Connector\2005.00.000\" key from the registry and it still returns error.

any suggestions?

 
this code worked fine for me on my system. You might want to look at the actual errors:

If Err Then
'Already been run, exit IF
Wscript.echo "CaseWare Connector 2005 Program not found:" & err.number & " " & Err.Description

Else
'---Removing CwConnector2005
WScript.Echo "CaseWare Connector 2005 found, Un-install required"'---For Testing Only
WSHShell.Run exeCwcUninstall, , True
Wscript.echo err.number & " " & Err.Description

End If

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
To properly identify the key not existing (rather than anything else), you can do this. (The conditional is localized. If the language of the os is not English, prepare to modify it accordingly.)
[tt]
WSHShell.RegRead(Cwc2005)
'[green]warning: description is localized, prepared to re-adapt the conditional[/green]
If Err[blue].number<>0 and lcase(left(Err.description,7))="invalid"[/blue] Then
'Already been run, exit IF
WScript.Echo "CaseWare Connector 2005 Program not found" '---For Testing Only
Else
'---Removing CwConnector2005
WScript.Echo "CaseWare Connector 2005 found, Un-install required" '---For Testing Only
WSHShell.Run exeCwcUninstall, , True
End If
[blue]err.clear[/blue]
[/tt]
There seems to be some silent change in the behaviour along the winnt-series of os itself. And that's why the checking seems very patchy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top