Hi,

I've used this line before:
If objFSO.FileExists("C:\Program Files\Microsoft
Office\Office10\Winword.exe") Then

Is there a method similar to this to check if a registry value exists?

Thanks in Advance,
JeffH

Re: Methods to use with the registry by Ray

Ray
Wed May 10 10:33:23 CDT 2006

Hi JeffH,

Yes, registry interaction capabilities are built into the WSH model. Do you
have the documentation for WSH? If not:

Download here:
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9

Or view online here:
http://msdn.microsoft.com/library/en-us/script56/html/60f96092-6021-42f3-9a27-6848f4c38f64.asp

Specific documentation on accessing the registry with VBScript using the
WshShellObject:
http://msdn.microsoft.com/library/en-us/script56/html/23f6169f-ebce-4ad9-a2e0-170de350e045.asp

Ray at work

"JeffH" <not@microsoft.com> wrote in message
news:ORQrVLEdGHA.4276@TK2MSFTNGP03.phx.gbl...
> Hi,
>
> I've used this line before:
> If objFSO.FileExists("C:\Program Files\Microsoft
> Office\Office10\Winword.exe") Then
>
> Is there a method similar to this to check if a registry value exists?
>
> Thanks in Advance,
> JeffH
>
>



Re: Methods to use with the registry by Richard

Richard
Wed May 10 11:31:44 CDT 2006

Hi,

There is not a KeyExists function, but you can make one. You would trap the
error raised when you attempt to read the value. For example:

Option Explicit
Dim strKey, objShell

strKey = "HKLM\Software\MyApp\Version"
Set objShell = CreateObject("Wscript.Shell")

If KeyExists(strKey) Then
Wscript.Echo "Key exists"
Else
Wscript.Echo "Key does NOT exist"
End If

Function KeyExists(ByVal strKey)
' Function returns True if strKey exists, False otherwise.
' The variable objShell should be declared with global scope.

Dim strValue
On Error Resume Next
strValue = objShell.RegRead(strKey)
If (Err.Number = 0) Then
On Error GoTo 0
KeyExists = True
Else
On Error GoTo 0
KeyExists = False
End If
End Function

You can do something similar using WMI, although an error is not raised.
Instead, the value read is Null.

Option Explicit
Dim strComputer, objReg, strKeyPath, strEntryName, strValue
Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\MyApp"
strEntryName = "Version"

objReg.GetStrValue strHive, strKeyPath, strEntryName, strValue

If (TypeName(strValue) = "String") Then
Wscript.Echo "Key exists"
Else
Wscript.Echo "Key does NOT exist"
End If

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:ur4GUcEdGHA.2456@TK2MSFTNGP04.phx.gbl...
> Hi JeffH,
>
> Yes, registry interaction capabilities are built into the WSH model. Do
> you have the documentation for WSH? If not:
>
> Download here:
> http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9
>
> Or view online here:
> http://msdn.microsoft.com/library/en-us/script56/html/60f96092-6021-42f3-9a27-6848f4c38f64.asp
>
> Specific documentation on accessing the registry with VBScript using the
> WshShellObject:
> http://msdn.microsoft.com/library/en-us/script56/html/23f6169f-ebce-4ad9-a2e0-170de350e045.asp
>
> Ray at work
>
> "JeffH" <not@microsoft.com> wrote in message
> news:ORQrVLEdGHA.4276@TK2MSFTNGP03.phx.gbl...
>> Hi,
>>
>> I've used this line before:
>> If objFSO.FileExists("C:\Program Files\Microsoft
>> Office\Office10\Winword.exe") Then
>>
>> Is there a method similar to this to check if a registry value exists?
>>
>> Thanks in Advance,
>> JeffH
>>
>>
>
>



Re: Methods to use with the registry by Fosco

Fosco
Wed May 10 21:39:50 CDT 2006

"JeffH"
> I've used this line before:
> If objFSO.FileExists("C:\Program Files\Microsoft
> Office\Office10\Winword.exe") Then
>
> Is there a method similar to this to check if a registry value exists?

generic sample :

Set oShell = WScript.CreateObject("WScript.Shell")
skey = oShell.RegRead("HKLM\Software\Microsoft\Windows\"&_
"CurrentVersion\ProgramFilesDir")
msgbox skey

WScript.Echo oShell.RegRead("HKEY_CLASSES_ROOT\"&_
"Paint.Picture\shell\open\command\")

http://www.winguides.com/scripting/library.php?id=5

--
Fosco