Ryan Taylor
2010-11-09 22:13:09 UTC
Note: This question is also posted at http://stackoverflow.com/questions/4138324/silently-executing-a-powershell-script-from-wix-hangs-powershell.
I am trying to silently execute a PowerShell script from a WiX produced MSI. However, anytime I run the installer PowerShell hangs. This in turn hangs the installation process. PowerShell is running the script "properly" in that the script is able to make changes to the system and no errors are reported. Interestingly, if I kill the PowerShell process via Task Manager, the installer cancels the installation and rolls back any changes.
--------------------------------------------------------------------------------
My PowerShell Script
--------------------------------------------------------------------------------
# @param website The website under which the module should be compiled and registered.
# @param name The name of the module to be registered.
# @param assembly The assembly name, version, culture and public key token to be compiled.
# @param assemblyType The fully qualified assemebly type to be registered.
param([string]$website = "website", [string]$name = "name", [string]$assembly = "assembly", [string]$assemblyType= "assemblyType")
import-module webadministration
add-webconfiguration /system.web/compilation/assemblies "IIS:\sites\$website" -Value @{assembly="$assembly"}
new-webmanagedmodule -Name "$name" -Type "$assemblyType" -PSPath "IIS:\sites\$website"
--------------------------------------------------------------------------------
Wix Custom Action Contents : Attempt 1
My first attempt at this was to use the & special character to execute the script
--------------------------------------------------------------------------------
<CustomAction Id="RegisterHttpModulePSCmd"
Property="RegisterHttpModulePowerShellProperty"
Value=""C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" &'C:\Program Files (x86)\My Company\Scripts\register-httpmodule.ps1' -website 'Default Web Site' -name 'MyCustomModule' -assembly 'MyCompany.Product.Feature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx' -assemblyType 'MyCompany.Product.Feature.MyModule'"
Execute="immediate" />
<CustomAction Id="RegisterHttpModulePowerShellProperty"
BinaryKey="WixCA"
DllEntry="CAQuietExec64"
Execute="deferred"
Return="check"
Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="RegisterHttpModulePSCmd" After="CostFinalize">NOT Installed</Custom>
<Custom Action="RegisterHttpModulePowerShellProperty" After="InstallFiles">NOT Installed</Custom>
</InstallExecuteSequence>
--------------------------------------------------------------------------------
Wix Custom Action Contents : Attempt 2
My second attempt was to use the -File argument to execute the script.
--------------------------------------------------------------------------------
<CustomAction Id="RegisterHttpModulePSCmd"
Property="RegisterHttpModulePowerShellProperty"
Value=""C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NonInteractive -NoProfile -File "C:\Program Files (x86)\My Company\Scripts\register-httpmodule.ps1" -website "Default Web Site" -name "MyCustomModule" -assembly "MyCompany.Product.Feature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" -assemblyType "MyCompany.Product.Feature.MyModule""
Execute="immediate" />
<CustomAction Id="RegisterHttpModulePowerShellProperty"
BinaryKey="WixCA"
DllEntry="CAQuietExec64"
Execute="deferred"
Return="check"
Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="RegisterHttpModulePSCmd" After="CostFinalize">NOT Installed</Custom>
<Custom Action="RegisterHttpModulePowerShellProperty" After="InstallFiles">NOT Installed</Custom>
</InstallExecuteSequence>
--------------------------------------------------------------------------------
Both approaches seem to work as they make modifications to the desired web.config file, however, both approaches hang PowerShell and thus the installer.
How do I silently execute a PowerShell script from Wix without hanging PowerShell?
Ryan Taylor
Office (207)-504-5294
***@penbaysolutions.com
www.penbaysolutions.com
CONFIDENTIALITY NOTICE:
This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please do not read, disclose, reproduce, distribute, disseminate or otherwise use this transmission, but contact the sender by reply e-mail and destroy all copies of the message and its attachments.
I am trying to silently execute a PowerShell script from a WiX produced MSI. However, anytime I run the installer PowerShell hangs. This in turn hangs the installation process. PowerShell is running the script "properly" in that the script is able to make changes to the system and no errors are reported. Interestingly, if I kill the PowerShell process via Task Manager, the installer cancels the installation and rolls back any changes.
--------------------------------------------------------------------------------
My PowerShell Script
--------------------------------------------------------------------------------
# @param website The website under which the module should be compiled and registered.
# @param name The name of the module to be registered.
# @param assembly The assembly name, version, culture and public key token to be compiled.
# @param assemblyType The fully qualified assemebly type to be registered.
param([string]$website = "website", [string]$name = "name", [string]$assembly = "assembly", [string]$assemblyType= "assemblyType")
import-module webadministration
add-webconfiguration /system.web/compilation/assemblies "IIS:\sites\$website" -Value @{assembly="$assembly"}
new-webmanagedmodule -Name "$name" -Type "$assemblyType" -PSPath "IIS:\sites\$website"
--------------------------------------------------------------------------------
Wix Custom Action Contents : Attempt 1
My first attempt at this was to use the & special character to execute the script
--------------------------------------------------------------------------------
<CustomAction Id="RegisterHttpModulePSCmd"
Property="RegisterHttpModulePowerShellProperty"
Value=""C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" &'C:\Program Files (x86)\My Company\Scripts\register-httpmodule.ps1' -website 'Default Web Site' -name 'MyCustomModule' -assembly 'MyCompany.Product.Feature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx' -assemblyType 'MyCompany.Product.Feature.MyModule'"
Execute="immediate" />
<CustomAction Id="RegisterHttpModulePowerShellProperty"
BinaryKey="WixCA"
DllEntry="CAQuietExec64"
Execute="deferred"
Return="check"
Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="RegisterHttpModulePSCmd" After="CostFinalize">NOT Installed</Custom>
<Custom Action="RegisterHttpModulePowerShellProperty" After="InstallFiles">NOT Installed</Custom>
</InstallExecuteSequence>
--------------------------------------------------------------------------------
Wix Custom Action Contents : Attempt 2
My second attempt was to use the -File argument to execute the script.
--------------------------------------------------------------------------------
<CustomAction Id="RegisterHttpModulePSCmd"
Property="RegisterHttpModulePowerShellProperty"
Value=""C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NonInteractive -NoProfile -File "C:\Program Files (x86)\My Company\Scripts\register-httpmodule.ps1" -website "Default Web Site" -name "MyCustomModule" -assembly "MyCompany.Product.Feature, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" -assemblyType "MyCompany.Product.Feature.MyModule""
Execute="immediate" />
<CustomAction Id="RegisterHttpModulePowerShellProperty"
BinaryKey="WixCA"
DllEntry="CAQuietExec64"
Execute="deferred"
Return="check"
Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="RegisterHttpModulePSCmd" After="CostFinalize">NOT Installed</Custom>
<Custom Action="RegisterHttpModulePowerShellProperty" After="InstallFiles">NOT Installed</Custom>
</InstallExecuteSequence>
--------------------------------------------------------------------------------
Both approaches seem to work as they make modifications to the desired web.config file, however, both approaches hang PowerShell and thus the installer.
How do I silently execute a PowerShell script from Wix without hanging PowerShell?
Ryan Taylor
Office (207)-504-5294
***@penbaysolutions.com
www.penbaysolutions.com
CONFIDENTIALITY NOTICE:
This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please do not read, disclose, reproduce, distribute, disseminate or otherwise use this transmission, but contact the sender by reply e-mail and destroy all copies of the message and its attachments.