I was successful with the following:

<Property Id="POWERSHELLEXE">
        <RegistrySearch Id="POWERSHELLEXE" Root="HKLM" 
Key="SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" Name="Path" 
Type="raw" />
</Property>

<CustomAction Id="CACmd" Property="POWERSHELLEXE" ExeCommand="-NoLogo 
-NoProfile -NonInteractive -Command . (Join-Path (Get-Item 
env:\PRODUCT_HOME).Value UninstallScript.ps1) -roleName $(var.ServerRole)" 
Return="check" Execute="deferred" />

<InstallExecuteSequence>
        <Custom Action="CACmd" Before="ProcessComponents">Installed AND NOT 
REINSTALL</Custom>
</InstallExecuteSequence>

The downside to this approach is that a command window shows up during 
uninstall. On the other hand the script gets executed properly.

I was hoping to use something like the following:

<Property Id="POWERSHELLEXE">
        <RegistrySearch Id="POWERSHELLEXE" Root="HKLM" 
Key="SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" Name="Path" 
Type="raw" />
</Property>

<CustomAction Id="CACmdLine" Property="CACmd" 
Value="&quot;[POWERSHELLEXE]&quot; -NoLogo -NoProfile -NonInteractive -Command 
. (Join-Path (Get-Item env:\PRODUCT_HOME).Value UninstallScript.ps1) -roleName 
$(var.ServerRole)" />
<CustomAction Id="CACmd" BinaryKey="WixCA" DllEntry="CAQuietExec" 
Return="check" Execute="deferred" />

<InstallExecuteSequence>
        <Custom Action="CACmdLine" Before="ProcessComponents">Installed AND NOT 
REINSTALL</Custom>
        <Custom Action="CACmd" After="CACmd">Installed AND NOT 
REINSTALL</Custom>
</InstallExecuteSequence>

This second style should execute powershell without showing the command window 
which would be ideal.

Both the MSI and the target server are 32-bit. I don't think I'm having a 
64-bit issue.

--
Edwin

-----Original Message-----
From: Dale Quigg [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 25, 2008 3:48 PM
To: 'wix-users@lists.sourceforge.net'
Cc: Castro, Edwin (Hillsboro)
Subject: Executing a PowerShell Script as Custom Action

> Date: Tue, 25 Nov 2008 14:10:24 -0500
> From: "Castro, Edwin (Hillsboro)" <[EMAIL PROTECTED]>
> Subject: [WiX-users] Executing a PowerShell Script as Custom Action

> I'm trying to execute a powershell script as custom action and I see
> the powershell.exe process starts but then it appears to be doing
> nothing. Here's an example:
>
<snip>
> I would expect powershell to print a value to its console and
> exit quickly. Instead, powershell.exe appears to hang until
> terminated manually. Am I doing something wrong?

Hi Edwin,

I've run into this same problem.  If I remember correctly, it was because I had 
a 64-bit install but the version of powershell that was being executed was 
32-bit (or the other way around).

I know I ended up creating a vbscript custom action which I marked with 
Win64="yes".  Then this picked up the correct version (64-bit in my case) of 
powershell.

Here's a snippet of my script.  The syntax for calling powershell scripts from 
cmd.exe is a bit tricky so I've included it.

  cmdshell = "cmd.exe /c "
  cmd = cmdshell & "echo " & action & " agents in Microsoft Exchange.  This may 
take several minutes... & powershell.exe -Command " & chr(34) &  ". " & chr(39) 
& script_dir & "AgentMain.ps1" & chr(39) & " " & action & chr(34)
  ret = oShell.Run(cmd,1,true)
  ' ret is kind of useless here since Powershell doesn't seem to propogate it's 
exit status to cmd.exe


Hope this helps.
Dale


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to