cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Launching Powershell Script from Supportdir using installscript Customaction

Launching Powershell Script from Supportdir using installscript Customaction

Launching Powershell Script from Supportdir using installscript Customaction 

Summary

Example on running  powershell script from Supportdir using installscript LaunchAppAndWait 

Synopsis

This article will show you different ways you can run your Powershell script using installscript custom action in Basic MSI and Installscript MSI Project Types

Discussion

If you want to run your powershell custoamction from support directory using installscript, you can follow below steps

Open your project, Select support files under "Behavior and Logic" and add your script ps1 file.

Now in your project, go to the 'Behavior and Logic->InstallScript' view and under the 'InstallScript->Files' node, right click and add a new 'setup.rul' file (...assuming no file is present already, if so, then skip this).

Once you have the 'setup.rul' file in your project, then there should be a default function added to the script called MyFunction(). You can keep this function name or change it (...remember to update the prototype as well) and you can use the following code...

 

 

 

 

function MyFunction(hMSI)
// To Do: Declare local variables.

STRING sMySUPPORTDIR, szCmd, szParam, szCmdLine ;
NUMBER nvBufferSize;

begin

// To Do: Write script that will be executed when MyFunction is called.
nvBufferSize = 256;

//Get SupportDir value
MsiGetProperty(hMSI,"SUPPORTDIR", sMySUPPORTDIR, nvBufferSize);

//MessageBox("SUPPORTDIR = " + sMySUPPORTDIR, INFORMATION);

// Setup command line to run ps1 file
szParam=WINSYSDIR64^"WindowsPowerShell\\v1.0\\powershell.exe";
szCmd=sMySUPPORTDIR^"CreateFolderPowershell.ps1";
//szCmd=sMySUPPORTDIR^"test.ps1";
LongPathToQuote(szCmd, TRUE);

szCmdLine=" -file "+szCmd;
//Running Script with Admin Privileges
LAAW_SHELLEXECUTEVERB = "runas";

if (AskYesNo(" Do you like to run our Powershell Script? Which will modify your system settings", YES) = YES) then

Disable(WOW64FSREDIRECTION);

//LAAW_OPTION_HIDDEN is used to hide the powershell window

LaunchAppAndWait(szParam, szCmdLine, LAAW_OPTION_WAIT| LAAW_OPTION_SHOW_HOURGLASS|LAAW_OPTION_HIDDEN);

endif;

end;

 

 

 

 // If we want to run script after user confirmation

   if (AskYesNo(" Do you like to run our Powershell Script? Which will modify your system settings", YES) = YES) then

      Disable(WOW64FSREDIRECTION); 

	LaunchAppAndWait(szParam, szCmdLine, LAAW_OPTION_WAIT| LAAW_OPTION_SHOW_HOURGLASS);

    endif;

 

 

 

 

 

Predefined Constants 

Calling a PowerShell Custom Action 

64bit Powershell Scripts not running  

LAAW_OPTION_HIDDEN 

 

No ratings
Version history
Last update:
‎Jan 25, 2022 09:04 PM
Updated by:
Contributors