Link to home
Start Free TrialLog in
Avatar of aero-owner
aero-owner

asked on

check if key exists with batch file or vbs

Basically I need to see if the following key exists:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-A00000000001}

If it does...run:

MsiExec /qb /X{AC76BA86-7AD7-1033-7B44-A00000000001}

if not...just keep on going in the batch or vbs..


don't care if it's a batch file or VBS...

Thanx in advance.

High points cause I need this fast.

Brian
Avatar of sramesh2k
sramesh2k
Flag of India image

Brian,

You may use this .VBS

=======================================

Dim oShell
Set oShell = CreateObject("WScript.Shell")
sKeyPath= "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-A00000000001}"
If RegKeyExists(sKeyPath) then
  oShell.Run "MsiExec /qb /X{AC76BA86-7AD7-1033-7B44-A00000000001}"
Else
   'Key doesn't exist
end if

Function RegKeyExists(ByVal sRegKey)
  ' Returns True or False based on the existence of a registry key.
  ' This part is a compliment from Torgeir Bakken.

  Dim sDescription

  RegKeyExists = True
  sRegKey = Trim (sRegKey)
  If Not Right(sRegKey, 1) = "\" Then
    sRegKey = sRegKey & "\"
  End If

  On Error Resume Next
  oShell.RegRead "HKEYNotAKey\"
  sDescription = Replace(Err.Description, "HKEYNotAKey\", "")

  Err.Clear
  oShell.RegRead sRegKey
  RegKeyExists = sDescription <> Replace(Err.Description, sRegKey, "")
  On Error Goto 0
End Function
=======================================
Avatar of aero-owner
aero-owner

ASKER

Awesome! works great!

one last thing (and I'll make a new question if you want)

after that...how would I, then, run in vbs:

oShell.Run "MsiExec /qb /I ""AcroStan.msi"" TRANSFORMS=""AcroStan.mst"" REBOOT=ReallySupress"
oShell.Run "msiexec /qb /i ""Adobe Acrobat 7.0.1 and Reader 7.0.1 Update.msi"""
oShell.Run "msiexec /qb /i ""Adobe Acrobat 7.0.2 and Reader 7.0.2 Update.msi"""

without them all running at once? can't find any sort of wait function.
ASKER CERTIFIED SOLUTION
Avatar of sramesh2k
sramesh2k
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial