[wix-users] Running PowerShell script after installer finishes

manish duggal duggal_sunny at yahoo.com
Thu Jun 14 22:57:27 PDT 2018


 Thats a great catch. I missed looking at the log ahead. Here is what I see further in the log
Action start 16:58:02: LaunchUpdaterCmdlet.
Action ended 16:58:24: LaunchUpdaterCmdlet. Return value 1.

Surprisingly, between these 22 seconds I see different PowerShell modules available in the machine getting loaded. But nothing really for the Script.ps1 in the call. 
I am going to try the absolute path for powershell.exe to see if that helps. 
    On Thursday, June 14, 2018, 10:42:48 p.m. PDT, Edwin Castro <egcastr at gmail.com> wrote:  
 
 That snippet of log shows the SetProperty running but not the actual custom action. What happens next in the log?
--Edwin G. Castro

On Thu, Jun 14, 2018, 22:35 manish duggal <duggal_sunny at yahoo.com> wrote:

 Hello Edwin,
The verbose log details are
MSI (s) (D0:AC) [18:26:03:717]: Doing action: SetLaunchUpdaterCmdletAction ended 18:26:03: InstallFinalize. Return value 1.MSI (s) (D0:AC) [18:26:03:717]: PROPERTY CHANGE: Modifying LaunchUpdaterCmdlet property. Its current value is 'TO_BE_OVERRIDDEN'. Its new value: '"powershell.exe" -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command "& 'C:\Program Files\Installer\Script.ps1' -InstallDir 'C:\Program Files\Installer\';"'.Action start 18:26:03: SetLaunchUpdaterCmdlet.MSI (s) (D0:AC) [18:26:03:717]: Doing action: SetLaunchUpdaterCmdletAction ended 18:26:03: SetLaunchUpdaterCmdlet. Return value 1.
Call to Script.ps1 should run the cmdlet and create a log file. When I try to run the Script.ps1 outside of installer, I see the cmdlet executed and log file created. However when I run the Script.ps1 from a CustomAction, I dont see cmdlet really running and log file being created. 
What else could I try to debug?

ThxManish 
    On Thursday, June 14, 2018, 10:24:06 p.m. PDT, Edwin Castro <egcastr at gmail.com> wrote:  
 
 Thanks for the details.
I don't see anything obviously wrong.
Are you using absolute paths for files? The working directory might not be what you expect. In your original email it looks like the script path is absolute but powershell.exe is not. Don't know if that makes a difference.
What does your verbose log say?
--Edwin G. Castro

On Thu, Jun 14, 2018, 22:11 manish duggal <duggal_sunny at yahoo.com> wrote:

 Hello Edwin,
Here are the details:
1. I have Script.ps1 which consist of command to invoke a PowerShell module and cmdlet. The Script.ps1 consist of the following command: 
Start-Process "powershell.exe" -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"& Import-Module PowerShellModule.psm1; Cmdlet `" "  -Verb RunAs

Start-Process cmdlet will launch a new PowerShell process elevated (-Verb RunAs)
2. To call my Script.ps1 with above details, I run following detail on command prompt:        "powershell.exe" -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command "& 'Script.ps1' ;"

So you are right in assuming that I try the script invocation on a command prompt. And due to Start-Process with "-Verb RunAs" the command in Script.ps1 launches elevated. 
I hope this clarifies the scenario I mentioned to try the script manually.
Please let me know how can I mimic this in WIX to call Script.ps1 after installer finishes. Right now, my attempt didnt really work to call the Script.ps1 and thus not running new PowerShell process elevated. 
ThxManish     On Thursday, June 14, 2018, 9:08:33 p.m. PDT, Edwin Castro <egcastr at gmail.com> wrote:  
 
 Yes, the details matter. I still don't know how you manually invoked the script so I can't help.
Normally executables can be configured with a manifest that tells the operating system that they must be executed elevated. Clearly such a manifest would apply to powershell.exe itself and not to your script so I don't know how you got the script to "ask for elevation" manually.
Once you share the details I might be able to help you figure out how to duplicate the behavior in MSI. The behavior you are seeing with the MSI is what I would expect under normal circumstances running your script.
Without more information I can only guess that in your manually case you actually elevated powershell or the command prompt yourself and then ran the script. Is that what you mean? That the script works properly when executed in an elevated process?
--Edwin G. Castro

On Thu, Jun 14, 2018, 20:35 <duggal_sunny at yahoo.com> wrote:

By manual, I mean out of installer actions. I just wanted to say that powershell command I specified in the installer does work fine when ran independent of installer.
ThxManish 

Sent from my iPhone
On Jun 14, 2018, at 6:39 PM, Edwin Castro <egcastr at gmail.com> wrote:


What do you mean by "I was able to invoke my script manually and it does ask for the elevation"? Which precise steps do you take to invoke the script manually?
--Edwin G. Castro

On Thu, Jun 14, 2018, 17:23 manish duggal via wix-users <wix-users at lists.wixtoolset.org> wrote:

Hi
I have a requirement to launch a powershell script after my installer finishes. My requirement is to launch it and ask for elevation if needed. I was able to invoke my script manually and it does ask for the elevation. However, the custom action in installer doesn't somehow launching the script. 
Here is my custom action detail
<Property Id='LaunchAction' Value='TO_BE_OVERRIDDEN' />        <SetProperty Id='LaunchAction'                      Value='"powershell.exe" -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command "& '[INSTALLDIR]Script.ps1' -InstallDir '[INSTALLDIR]';"'                     Before='LaunchAction                      Sequence='execute' />        <CustomAction Id='LaunchAction'                      BinaryKey='WixCA'                      DllEntry='CAQuietExec64'                      Execute='immediate'                      Return='ignore'                      Impersonate='no'/>
Why it is not getting invoked correctly after installer finishes? I looked at "WixShellExecTarget" but not sure if this could really be used to run a PowerShell script with parameters. 
Appreciate help in this regard. 
ThxManish 

____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant http://www.firegiant.com/


  
  
  


More information about the wix-users mailing list