codewario
codewario

Reputation: 21418

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?

Upvotes: 7

Views: 8905

Answers (2)

codewario
codewario

Reputation: 21418

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")

Upvotes: 9

Bogdan Mitrache
Bogdan Mitrache

Reputation: 10993

If you just have a simple project includes some merge modules and the applications' files you can use a better tool, Advanced Installer. For what you need you can use the free version, i.e. create a "Simple" project type. Adding the merge modules and files will not take you more than a minute.

Now it comes the easy part were you completely get rid of your custom actions, to create the shortcuts you can go to Files and Folders page and using the context menu options, or toolbar, you can create an external shortcut, which you can configure to point to a file from the merge module, or even not from the package.

This way you can create a much cleaner setup package, much easier and don't have to worry about the chance of your custom actions failing.

Upvotes: 3

Related Questions