Clean Up the Windows Start Menu

Sometimes after an install or an uninstall we want to clean up the start menu – usually this involves removing shortcuts to uninstall the application, shortcuts that link to help files and/or shortcuts that attempt to install additional components.  This tidy script (tested on Windows 7) can be used to populate file(s) and folder(s) names that require deleting.

 

Access a Windows Installer property in a Deferred Custom Action

Description:

This post describes how to access a Windows Installer property in a Deferred Custom Action.  Deferred, commit, and rollback custom actions can only access a limited number of built-in Windows Installer properties – CustomActionData, ProductCode, and UserSID.  In brief (since this has been discussed plenty of times before elsewhere) this is due to them being executed in a separate process (they spawn another MSIEXEC.exe process which is run in a System Account context – check Task Manager during an installation to see this).  To pass any Windows Installer property to a deferred Custom Action, we must pass it via the CustomActionData property.  In this example, we’ll pass the ProductName property during the installation of our product.

Step 1
Create a property. Call it ‘AlkaneCustomProperty’ and give it a default value of anything (we’re going to set this to our directory name in Step 2….).

Step 2
Create a SetProperty custom action (Type 51), call it ‘setAlkaneCustomProperty’, select your ‘AlkaneCustomProperty’ property, and under property value write ‘[ProductName]’. Execute this action as Immediate, before InstallInitialize with a condition of ‘NOT Installed’.

Step 3
Create another CA – this time a ‘Call VBScript from Embedded code’ (Type 38). It is IMPORTANT you call this the same name as your property you made earlier, so call it ‘AlkaneCustomProperty’. In your script, to retrieve the directory name use:

Schedule this CA as ‘Deferred in a System Context’ and put it anywhere between the standard actions ‘InstallInitialize’ and ‘InstallFinalize’.  Use a condition of ‘NOT Installed’.

Use VBScript to amend the the Hosts/Services or any other text file

Description:

This post shows how to use VBScript to amend the the Hosts/Services or any other text file.  It contains two scripts to add/remove lines of text.  This example adds to the C:\Windows\System32\drivers\etc\Services file.

Source:

N/A

Script:

Add to Services file

Remove from Services file

 

Create a Nested Folder Structure using VBScript

Description:

The Filesystem Object cannot create a nested folder structure in a single invocation of the CreateFolder method.  For example, if we tried executing the following code it would return a ‘Path Not Found’ error unless c:\alkanesolutions\ already exists:

objFSO.CreateFolder “c:\alkanesolutions\test\”

The function below resolves this limitation.

Source:

Technet Forums

Script:

 

 

Extract an EXE from the binary table and run it from a VBScript Custom Action

Somebody over at ITNinja recently asked how they could run an executable stored in the binary table, from a VBScript Custom Action. Here’s an example I knocked up which describes how to extract an EXE from the binary table and run it from a VBScript Custom Action. I basically streamed notepad.exe into the binary table, and gave it a name of ‘notepad’.  In this Custom Action, I extract it to the %temp% folder and run it from there.  Note that there is no cleanup of the extraction afterwards.  Also note that because this uses the Session object, it can only be executed in the Immediate context.  So more consideration would be required (and probably a separate Custom Action) to execute the extracted EXE in a deferred context.

Alternatives to using WScript.Sleep in a Custom Action

Description:

Sometimes in our Custom Actions we need to pause the script execution, for example when we’re manipulating processes. Since we can’t use Wscript.Sleep from a Custom Action we need another way of pausing the execution of a script. Here I present two alternatives to using WScript.Sleep in a Custom Action.

Source:

NA

Script 1:

Script 2:

Kill One or Many Processes

Description:

Useful when we want to terminate processes during uninstall.  Sometimes when processes are still running during uninstall it may cause the uninstall to fail or not remove all files. This script is an example of how to kill one or many processes.

Source:

NA

Script:

Using Windows Management Instrumentation:

 

Or using Windows Script Host:

 

Check if a Folder is Empty (contains no files and no subfolders)

Description:

Useful when we want to delete folders which have been left behind after uninstall, but we first need to check that the folder is actually empty!! An example may be a folder named as the vendor (E.g, ‘Adobe’), where other products could also be installed into the same folder (E.g, Acrobat Reader, Acrobat Standard, Creative Suite etc). This script will check if a folder is empty (contains no files and no subfolders) and delete it if so.

Source:

www.winfrastructure.net

Script:

 

Delete a Registry Key and its Subkeys

Description:

Useful when we want to delete registry which has been left behind post uninstall.

Source:

technet.microsoft.com

Script: