[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1009
  • Last Modified:

vbscript : need a way to check the existence of of a registry key

Is there something like fso.fileexists but for registry keys instead of files ?
0
itbabe
Asked:
itbabe
1 Solution
 
basicinstinctCommented:
I think you have to write code to check if it exists.  I did something like this before (to check if an application was installed by looking for it in the registry).  You could try something like that.  Here's the code:

'START EXAMPLE CODE

If isInstalled("Mozilla Firefox (1.0.4)") Then
    MsgBox("The application is installed :)")
Else
     MsgBox("The application is NOT installed :(")
End If

Function isInstalled(strAppName)
     Const HKEY_LOCAL_MACHINE = &H80000002
     retVal = false
     strComputer = "."
     strAppName = LCase(strAppName)
     Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
     strComputer & "\root\default:StdRegProv")
     
     strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
     oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
     
     For Each subkey In arrSubKeys
          'MsgBox(subkey) 'uncomment this line for demo purposes
          If strAppName = LCase(subkey) Then
               retVal = true
               Exit For
          End If
     Next
     isInstalled = retVal
End Function

'END EXAMPLE CODE

http://www.experts-exchange.com/Programming/Q_21835437.html
0
 
TrystnCommented:
Hi itbabe,

You'll find a script here http://ourworld.compuserve.com/homepages/Guenter_Born/WSHBazaar/WSH2.htm#L7 which allows you to confirm the existence of a registry key using the regread command in WSH.

There is some concern over error handling so another script can be found here:

http://www.fpschultze.de/modules/smartfaq/faq.php?faqid=48

Cheers
Trystn
0
 
cschipperCommented:
we use a script that check the registry if SMS client is installed hope this helps:

Option Explicit
on error resume next
Dim WSHShell
Dim RegKey
Dim waarde
Dim wshEnvironment
Dim strRunProgram
Set WSHShell = CreateObject("WScript.Shell")
Set wshEnvironment = wshShell.Environment("System")
RegKey = "HKLM\SOFTWARE\Microsoft\SMS\Mobile Client\"
waarde = WSHShell.RegRead(RegKey & "AssignedSiteCode")
if not waarde = "123" Then

Call installsms
Else
WScript.echo "SMS Client is geinstalleerd"
End If

Function installsms()
strRunProgram = "\\1234\SMSClient\i386\client.msi"
WshShell.Run strRunProgram, 1, True

End Function
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now