Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing a script file from a Windows Installer Custom Action

I need to execute a batch file as part of the un-install process in a Windows installer project (standard OOTB VS 2008 installer project-vdproj). One cannot execute a bat file directly from the Custom Actions in the installer project, so I wrote a quick vbs script to call the required bat file.
vbs code:

Set WshShell = WScript.CreateObject( "WScript.Shell" )
command = "uninstall-windows-serivce.bat"
msgbox command
WshShell.Run ("cmd /C " & """" & command & """")
Set WshShell = Nothing

When this script is run independent of the uninstall, it works perfectly. However, when run as part of the uninstall, it does not execute the bat file (but the message box is shown, so I know the vbs file is called). No errors reported (at least that I can tell). Why doesn't this script work as part of the "Uninstall Custom Action"

like image 218
Dan Avatar asked Sep 19 '08 01:09

Dan


People also ask

Where do custom actions execute?

All file access during custom action execution is relative to the /opt/qradar/bin/ca_jail/ directory.

What is MSI custom action?

The custom actions are the actions that can be performed together with the MSI package install and/or uninstall process. They can be used, for example, to prepare the system for installation of the package, to check prerequisites, to start the application on installation completion, etc.

What are custom actions?

Custom actions are buttons that sales reps can click to perform an action in the quote line editor, configurator, or several other detail pages. For example, sales reps can select to show a filtered section of your price book or to direct users to an internal or external URL.


2 Answers

I've run into this same problem and the issue is that you can't call WScript within the vbs file - you will need to JUST call CreateObject

ie.

Set WshShell = CreateObject( "WScript.Shell" )
command = "uninstall-windows-serivce.bat"
msgbox command
WshShell.Run ("cmd /C " & """" & command & """")
Set WshShell = Nothing
like image 75
JustinD Avatar answered Sep 28 '22 10:09

JustinD


The wider you need to distribute your application, the more strongly I would recommend against scripted custom actions. I had written a bunch in the past, but I found that too many computers have problems running VBScript or JavaScript. I ended up rewriting them all in C++ to handle this situation. Here are a couple of posts that give an in-depth explanation on why you should avoid scripted custom actions:

  • VBScript (and Jscript) MSI CustomActions suck
  • VBScript (and Jscript) MSI Custom Actions (don't have to) suck
like image 36
LanceSc Avatar answered Sep 28 '22 11:09

LanceSc