PDA

View Full Version : RegRead: Key doesn't exist



Nailz
05-16-2002, 03:45 AM
How do I get the contents of a Registry key if it hasn't been populated yet?

Sounds odd, but the reason is that I have a script that will check for a reg key and, if empty, run some configuration settings then set the key. This way the next time the script runs it will see the key and quit.

But if a do something like:

myRegKey = wsh.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\PRE SET")

Where PRESET will be set to "1" for example if the script has already been run. The check would be:

If myRegKey = "" Then
... Run Configuration
... wsh.RegWrite"...\PRESET","1","REG_SZ"
End If

wscript.quit 1


The problem is that the script errors out because PRESET doesn't exist yet.

How do I get around this??

lmwinbur
05-17-2002, 02:25 AM
This should work for you... it check for a key and if not there it runs your app. If its there, it quits...

const RegKeyNotExist = -2147024894
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
on error resume next
WshShell.RegRead("HKLM\software\test\test")
if err.number = RegKeyNotExist then
WshShell.Run "c:\", 1, true
WshShell.RegWrite"HKLM\Software\test\test", "Value"
else
wscript.quit
end if