7

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?

codewario
  • 19,553
  • 20
  • 90
  • 159

2 Answers2

9

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")
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
codewario
  • 19,553
  • 20
  • 90
  • 159
  • WScript objects are not supported in VBS files running as a custom action. If you ever need to use this type of object the above method is the only one working. One another side, VBS custom actions are not my first recommendation, but it all depends on the time you have available for creating the setup package. VBS custom actions come with a lot of risks, like antivirus blocking or vscript engine failures an many others. A Win32 DLL would be the best choice for a custom action. – Bogdan Mitrache Jun 04 '12 at 15:25
  • Basically, I have this script, then another script to create shortcuts that are included inside of a merge module (Setup and Deployment projects do not offer the ability to link to files within merge modules), and a script that removes said shortcuts on uninstall. I went the vbs route to save time as I do not have time to learn how to create a custom action DLL. – codewario Jun 04 '12 at 15:35
3

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.

Bogdan Mitrache
  • 10,536
  • 19
  • 34
  • 1
    Good recommendation, but my client wishes to use the Setup and Deployment project as that is what his team is familiar with. And if I had my choice, I would probably use WiX since that is what I'm familiar with. – codewario Jun 05 '12 at 13:57