VBSCRIPT registry check? help!!!

Status
Not open for further replies.

hsbaker

Seniorius Lurkius
25
To access the registry, you need to create a Windows scripting host object. I haven't worked with it much at all, but should be something like

DIM wsh
DIM key
Set wsh = WScript.CreateObject("WScript.Shell")
key = wsh.RegRead "HKLM\software\microsoft\windows\
currentversion\runonce"
If key = "(whatever)" Then
'Do this
Else
'Do that
End If

Hope that helps. There's more info at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsObjWshShell.asp
 

MoonlitKnight

Ars Scholae Palatinae
888
That won't work hsbaker.. {I've tried}

What will happen is that if the key or value DOESN'T exist, you'll get a runtime error.

I don't remember the numerical codes, but I did it this way (and it works ok)

dim wshShell
set wshShell = createobject ("Wscript.shell")

const RegError = -214.... (don't remember the number)
on error resume next

dim strResult
strResult = wshShell.RegRead ("HKLM\software\microsoft\windows\currentversion\runonce")

if strResult = RegError then
'Key not found.. do something
else
'Key found.. do something

end if

set wshShell = nothing
 
Use "on error resume next" and query the err.number for a non-zero value.

code:<HR>
Code:
on error resume next
DIM wsh
DIM key
Set wsh = WScript.CreateObject("WScript.Shell")
key = wsh.RegRead( "HKLM\software\microsoft\windows\currentversion\runonce")
If (err.number <> 0) Then
	msgbox "error: " & err.number & ":" & err.description
end if
 
Status
Not open for further replies.