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;
Additional Information
Calling a PowerShell Custom Action
Related Articles
FlexNet agent (ndtrack) may trigger a security software warning due to PowerShell script execution containing unusual char… 74Number of Views HOW TO: Launch a bat file from INSTALLDIR/SUPPORTDIR using Custom Action 24Number of Views Update Suite Progress Bar using InstallScript CustomAction 5Number of Views PowerShell script to monitor the process and folders used by the cloud metering process 73Number of Views Configps1 PowerShell script fails when non default SQL Server port is used 19Number of Views
Hi, I am Reva - Ask me anything.
No new updates
Thanks for the feedback!
Your feedback has been saved.Rate this response:
Add Additional feedback ( Optional )
Are you sure you want to cancel
the case creation?
Are you sure you want to cancel the case creation?
Are you sure you want to close this case
| Products | Region | Phone Numbers |
|---|---|---|
| FlexNet Operations FlexNet Embedded FlexNet Publisher FlexNet Connect FlexNet Code Insight InstallAnywhere InstallShield |
North America * |
+1 630-332-2513 (toll) +1 877-279-2853 (toll-free in North America) |
| Europe * |
+44 1925 944367 (toll) +44 800 047 8642 (toll-free in Europe) |
|
| Japan * | +81 3-4540-5335 (select option 2) | |
| Australia * |
+61 3 9895 2177 +61 1800 560 603 (toll-free in Australia) |
|
|
Usage Intelligence (formerly
Revulytics) Compliance Intelligence |
Please use the Case Portal to submit your support ticket or reach out to your Revenera contact. | |
Case id: 00001065
Activity: Status change: 2 hours ago