0

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

bo gusman
  • 127
  • 1
  • 2
  • 9
  • I'm not familiar with installscript, so I'm not adding this as an answer, but... generally you can [call a vbs from the command line](https://technet.microsoft.com/en-us/library/bb490816.aspx?f=255&MSPPError=-2147217396) with `cscript.exe /path/to/your.vbs` I'm betting that would work in that second field from your screenprint. – JNevill Sep 18 '17 at 14:28
  • @JNevill - thanks for your idea - it led me to the solution in a round about way. It turns out that IS is smart enough to launch the vbs script as I have it. Due to idiosyncrasies in the IS UI, I hadn't specified the "condition" correctly. I've still got to jump through some other hoops to get the behavior that I want, but at least I'm on the right path. – bo gusman Sep 18 '17 at 16:18
  • That's great news! If you'd like you can add your solution as an answer here and mark it as such. This way if someone else in the future is stuck with the same issue, there will be some help here on SO :) – JNevill Sep 18 '17 at 16:22
  • Well, I'd be happy to add my solution as an answer, except that I have not been able to successfully take the concept to implementation. InstallScript (actually, it's an InstallShield InststallScript project) is the most frustrating tool I've ever used. It simply hasn't grown with the rest of the MS ecosystem. I can get my vbs working just fine from the command line, but from inside the IS prerequisite, it does not work properly, and I have no idea why. Ultimately, all i'm trying to do is look for a registry key, and that's apparently not allowed. :( – bo gusman Sep 18 '17 at 22:30

2 Answers2

0

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

```

Stephen Quan
  • 21,481
  • 4
  • 88
  • 75
0

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.

bo gusman
  • 127
  • 1
  • 2
  • 9