Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBScript will not execute correctly from MSI file

I have a VBScript I wrote that needs to be executed from an MSI file. The script correctly executes when I run it within Windows on its own, however, when I run it from the installer I get the following error as shown in the log file:

Microsoft VBScript runtime error: object required: 'WScript', Line 3, Column 2

The script is below:

sub shell(cmd)
    Set objShell = WScript.CreateObject("WScript.Shell")

    objShell.Run("""" & cmd & """")
    Set objShell = Nothing
end sub

set objFSO = CreateObject("Scripting.FileSystemObject")

strcmd32 = "C:\Path\PathToExecutable.exe"
strcmd64 = "C:\Path\PathToExecutable64.exe"

if (objFSO.FileExists(strcmd32)) then
    shell(strcmd32)
else 
    shell(strcmd64)
end if

set objFSO = Nothing

As stated before, this script runs fine if I run it outside the context of the installer. The setup project type is VS2010 Setup and Deployment Package (this is what the client wishes to use and I cannot use anything else). Any ideas?

like image 619
Bender the Greatest Avatar asked Jun 04 '12 13:06

Bender the Greatest


1 Answers

In the "shell" sub, I removed the WScript from the first line before the call to "CreateObject()". The amended line now looks like this:

'Note the absent reference to WScript on the call to CreateObject()
Set objShell = CreateObject("WScript.Shell")
like image 81
Bender the Greatest Avatar answered Sep 29 '22 20:09

Bender the Greatest