How to call VBScript in InstallScript project

418 views Asked by At

I want to use a VB Script script file as the target of an InstallScript project prerequisite. I need to use VB Script because I must check several different conditions that are not possible using the regular conditions in the IS prerequisite editor (i.e., operating system conditions are OR, other conditions are AND.)

I've seen the link here but it does not apply to an InstallScript project.

I've also tried simply naming the in the "Specify the application you wish to launch" combo, but that doesn't appear to be working. (The .vbs script simply displays a modal dialog so that I can test the basic functionality.)

Can this be done?

enter image description here

2

There are 2 answers

0
bo gusman On BEST ANSWER

It turns out that my VBS script was working all along, but I was not looking in the right part of the registry for the key I needed to make a decision on. On a 64 bit box, a 32 bit process looks at (is magically redirected to look at) the Wow6432Node subkey. So if I'm looking for the key

HKLM\Software\BoGusman

the process is actually looking at

HKLM\Software\Wow6432Node\BoGusman

The target key existed in the 64 bit registry but did not exist in Wow6432Node. Creating the key in both locations solved the problem.

Thanks to @JNevill and @Steven Quan for getting me on the right track.

0
Stephen Quan On

Debugging VBScripts in InstallShield is a pain in the neck. Old school debugging, i.e. writing to log files, is best, since, you won't be able to capture error messages, etc.

Also reading and writing to the registry from InstallShield can be done via winmgmts but it's a pain. Here's an example that demonstrates this. Since our app uses 32 bit registry keys and we didn't know if it was being processed by 32 bit or 64 bit Windows, we had to check both locations for the 32 bit registry key (i.e. the Wow6432Node).

Here's some code we used to read the registry:

Option Explicit

Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002

Dim SoftVersion
SoftVersion = RegReadString("HKLM\SOFTWARE\Co\Software\Version")
If SoftVersion = "" Then
  SoftVersion = RegReadString("HKLM\SOFTWARE\Wow6432Node\Co\Software\Version")
End If

Function RegReadString(path)
  ' RegRead = CreateObject("WScript.Shell").RegRead(path)
  Dim objReg, hkroot, pos, posNext, keyPath, valueName, value
  Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
  hkroot = HKEY_CURRENT_USER
  If Left(path, 5) = "HKCU\" Then
    hkroot = HKEY_CURRENT_USER
    path = Mid(path, 6)
  ElseIf Left(path, 5) = "HKLM\" Then
    hkroot = HKEY_LOCAL_MACHINE
    path = Mid(path, 6)
  End If
  pos = InStr(path, "\")
  posNext = InStr(pos + 1, path, "\")
  While posNext > 0
    pos = posNext
    posNext = InStr(pos + 1, path, "\")
  Wend
  keyPath = Left(path, pos - 1)
  valueName = Mid(path, pos + 1)
  objReg.GetStringValue hkroot, keyPath, valueName, value
  If IsNull(value) Then
    RegReadString = ""
  Else
    RegReadString = value
  End If
End Function

Sub RegWriteString(path, value)
  Dim objReg, hkroot, pos, posNext, keyPath, valueName
  Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
  hkroot = HKEY_CURRENT_USER
  If Left(path, 5) = "HKCU\" Then
    hkroot = HKEY_CURRENT_USER
    path = Mid(path, 6)
  ElseIf Left(path, 5) = "HKLM\" Then
    hkroot = HKEY_LOCAL_MACHINE
    path = Mid(path, 6)
  End If
  pos = InStr(path, "\")
  posNext = InStr(pos + 1, path, "\")
  While posNext > 0
    pos = posNext
    posNext = InStr(pos + 1, path, "\")
  Wend
  keyPath = Left(path, pos - 1)
  valueName = Mid(path, pos + 1)
  objReg.SetStringValue hkroot, keyPath, valueName, value
End Sub

```