Arvo Bowen
Arvo Bowen

Reputation: 4945

VBScript works great when I run it from command prompt but not from within Inno Setup

I have a VBScript that I wrote that works great! It does everything that I need it to perfectly when I run it from a command line in Windows 10.

cscript.exe "C:\SetupTempPath\MyScript.vbs" "First Param" 1234 "Third Param"

For some reason when I have it in my Inno Setup script...

Filename: "{sys}\cscript.exe"; \
  Parameters: """{tmp}\MyScript.vbs"" ""{code:GetStringValue}"" {#PORT} ""{#NAME}"""; \
  Description: "Set port to {#PORT}."; \
  StatusMsg: "Setting the port to {#PORT}."; \
  Tasks: setPortNumber; \
  Check: SetTcpPort({#PORT});

When I run setup in debug mode, it shows me the following...

[12:37:45.377] -- Run entry --
[12:37:45.378] Run as: Current user
[12:37:45.380] Type: Exec
[12:37:45.381] Filename: C:\WINDOWS\system32\cscript.exe
[12:37:45.425] Parameters: "C:\SetupTempPath\MyScript.vbs" "First Param" 1234 "Third Param"
[12:38:04.987] Process exit code: 0
[12:38:04.995] Need to restart Windows? No
[12:38:06.944] Deinitializing Setup.
[12:38:06.997] *** Setup exit code: 0

So as you can see everything is getting resolved successfully from code functions as well as Inno Setup constants (Definitions) that are defined.

I ended up putting a bunch of MsgBox lines in the VBScript to check the status and see when it errors out. I ended up finding out the part of the VBScript that it has an issue with (only when being ran from Inno Setup) so I adjusted the script to account for some error control and here is the results...

Set wmiComputer = GetObject(wmiObjectQuery)
Set tcpProperties = wmiComputer.ExecQuery(wmiQuery)

MsgBox "Break! Count: " & tcpProperties.Count
If Err.Number <> 0 Then
    MsgBox "Query returned no results.", 0, "Port not changed!"
    WScript.Quit
End If

Stepping through it EVERYTHING is exactly the same. The wmiObjectQuery string is the same, the wmiQuery I create is the same. I found no differences at all except ONE. When ExecQuery() is called and I'm running it from a command prompt (while setup is waiting for me to close it), it returns TWO records. On the other hand, when I let setup try and run it, that ends up tripping the error control because tcpProperties.Count fails (due to tcpProperties NOT being set).

So my question is, why does it work perfectly from a command prompt and not the Inno Setup script?

Upvotes: 3

Views: 1417

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202534

Just a guess: Inno Setup executes 32-bit cscript. While on command-line, you execute 64-bit cscript. That can make the difference.

Try adding the Flags: 64bit to your [Run] entry.


The Inno Setup installer is 32-bit application, so it will by default find 32-bit version of cscript (C:\Windows\SysWOW64\cscript).

See also Install Mode: 32-bit vs. 64-bit article in Inno Setup documentation.

Upvotes: 4

Related Questions