<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://nsis.sourceforge.io/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=CharlesB</id>
	<title>NSIS Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://nsis.sourceforge.io/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=CharlesB"/>
	<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/Special:Contributions/CharlesB"/>
	<updated>2026-04-23T21:14:35Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.17</generator>
	<entry>
		<id>https://nsis.sourceforge.io/mediawiki/index.php?title=User:CharlesB&amp;diff=24004</id>
		<title>User:CharlesB</title>
		<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=User:CharlesB&amp;diff=24004"/>
		<updated>2014-01-08T09:14:03Z</updated>

		<summary type="html">&lt;p&gt;CharlesB: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://forums.winamp.com/member.php?u=509744 Winamp forum profile]&lt;br /&gt;
&lt;br /&gt;
[http://stackoverflow.com/users/11343/charlesb Stack Overflow profile]&lt;/div&gt;</summary>
		<author><name>CharlesB</name></author>
	</entry>
	<entry>
		<id>https://nsis.sourceforge.io/mediawiki/index.php?title=User:CharlesB&amp;diff=24003</id>
		<title>User:CharlesB</title>
		<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=User:CharlesB&amp;diff=24003"/>
		<updated>2014-01-08T08:52:13Z</updated>

		<summary type="html">&lt;p&gt;CharlesB: Created page with &amp;quot;[http://forums.winamp.com/member.php?u=509744 Winamp forum profile]  [http://stackoverflow.com/users/11343/charlesb Stack Overflow profile]  [http://www.linkedin.com/in/chbros...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://forums.winamp.com/member.php?u=509744 Winamp forum profile]&lt;br /&gt;
&lt;br /&gt;
[http://stackoverflow.com/users/11343/charlesb Stack Overflow profile]&lt;br /&gt;
&lt;br /&gt;
[http://www.linkedin.com/in/chbrosso Linkedin profile]&lt;/div&gt;</summary>
		<author><name>CharlesB</name></author>
	</entry>
	<entry>
		<id>https://nsis.sourceforge.io/mediawiki/index.php?title=PowerShell_support&amp;diff=24002</id>
		<title>PowerShell support</title>
		<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=PowerShell_support&amp;diff=24002"/>
		<updated>2014-01-08T08:22:58Z</updated>

		<summary type="html">&lt;p&gt;CharlesB: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{PageAuthor|CharlesB}}&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
These macros simplify PowerShell use in NSIS, and overcome a bug of PowerShell v2, [[http://forums.winamp.com/showthread.php?p=2969465 described here]], and [[http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected reported here]]). &lt;br /&gt;
&lt;br /&gt;
PowerShellExec and PowerShellExecLog respectively place the script output on &lt;br /&gt;
the stack and in the log window&lt;br /&gt;
The same goes for PowerShellExecFile and PowerShellExecFileLog, which &lt;br /&gt;
are used to execute a PowerShell script file.&lt;br /&gt;
&lt;br /&gt;
If execution fails, the error level is set to 2.&lt;br /&gt;
&lt;br /&gt;
== How to use ==&lt;br /&gt;
&lt;br /&gt;
Save the script in a file named psexec.nsh, and place it next to your .nsi (or in the NSIS include directory). Then in your script, put an !include psexec.nsh, and call it like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;${PowerShellExec} &amp;quot;echo &#039;hello powershell&#039;&amp;quot;  &lt;br /&gt;
Pop $R1 ;$R1 is &amp;quot;hello powershell&amp;quot;&lt;br /&gt;
&lt;br /&gt;
InitPluginsDir&lt;br /&gt;
SetOutput $PLUGINSDIR\Powershell&lt;br /&gt;
File script.ps1&lt;br /&gt;
${PowerShellExecFileLog} &amp;quot;$PLUGINSDIR\Powershell\script.ps1&amp;quot; &amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In your PS commands, remember to escape the dollar sign by doubling it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;${PowerShellExec} &amp;quot;echo $$ProgramFiles&amp;quot;&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls ==&lt;br /&gt;
&lt;br /&gt;
Be aware that as long as the installer is a 32 bit process, the PowerShell interpreter&lt;br /&gt;
is also in 32 bit. This can cause redirections in filesystem, registry and environment&lt;br /&gt;
variables when running or 64 bit systems (see https://en.wikipedia.org/wiki/WoW64)&lt;br /&gt;
&lt;br /&gt;
Also I found that executing a file directly from $PLUGINSDIR caused errors in script execution, and that saving it in a $PLUGINSDIR subfolder prevented the errors. &lt;br /&gt;
&lt;br /&gt;
== The Script ==&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;&lt;br /&gt;
!ifndef PSEXEC_INCLUDED&lt;br /&gt;
!define PSEXEC_INCLUDED&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecMacro PSCommand&lt;br /&gt;
  InitPluginsDir&lt;br /&gt;
  ;Save command in a temp file&lt;br /&gt;
  Push $R1&lt;br /&gt;
  FileOpen $R1 $PLUGINSDIR\tempfile.ps1 w&lt;br /&gt;
  FileWrite $R1 &amp;quot;${PSCommand}&amp;quot;&lt;br /&gt;
  FileClose $R1&lt;br /&gt;
  Pop $R1&lt;br /&gt;
  &lt;br /&gt;
  !insertmacro PowerShellExecFileMacro &amp;quot;$PLUGINSDIR\tempfile.ps1&amp;quot;&lt;br /&gt;
!macroend&lt;br /&gt;
 &lt;br /&gt;
!macro PowerShellExecLogMacro PSCommand&lt;br /&gt;
  InitPluginsDir&lt;br /&gt;
  ;Save command in a temp file&lt;br /&gt;
  Push $R1&lt;br /&gt;
  FileOpen $R1 $PLUGINSDIR\tempfile.ps1 w&lt;br /&gt;
  FileWrite $R1 &amp;quot;${PSCommand}&amp;quot;&lt;br /&gt;
  FileClose $R1&lt;br /&gt;
  Pop $R1&lt;br /&gt;
  &lt;br /&gt;
  !insertmacro PowerShellExecFileLogMacro &amp;quot;$PLUGINSDIR\tempfile.ps1&amp;quot;&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecFileMacro PSFile&lt;br /&gt;
  !define PSExecID ${__LINE__}&lt;br /&gt;
  Push $R0&lt;br /&gt;
  &lt;br /&gt;
  nsExec::ExecToStack &#039;powershell -inputformat none -ExecutionPolicy RemoteSigned -File &amp;quot;${PSFile}&amp;quot;  &#039;&lt;br /&gt;
&lt;br /&gt;
  Pop $R0 ;return value is first on stack&lt;br /&gt;
  ;script output is second on stack, leave on top of it&lt;br /&gt;
  IntCmp $R0 0 finish_${PSExecID}&lt;br /&gt;
  SetErrorLevel 2&lt;br /&gt;
  &lt;br /&gt;
finish_${PSExecID}:&lt;br /&gt;
  Exch ;now $R0 on top of stack, followed by script output&lt;br /&gt;
  Pop $R0&lt;br /&gt;
  !undef PSExecID&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecFileLogMacro PSFile&lt;br /&gt;
  !define PSExecID ${__LINE__}&lt;br /&gt;
  Push $R0&lt;br /&gt;
  &lt;br /&gt;
  nsExec::ExecToLog &#039;powershell -inputformat none -ExecutionPolicy RemoteSigned -File &amp;quot;${PSFile}&amp;quot;  &#039;&lt;br /&gt;
  Pop $R0 ;return value is on stack&lt;br /&gt;
  IntCmp $R0 0 finish_${PSExecID}&lt;br /&gt;
  SetErrorLevel 2&lt;br /&gt;
  &lt;br /&gt;
finish_${PSExecID}:&lt;br /&gt;
  Pop $R0&lt;br /&gt;
  !undef PSExecID&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!define PowerShellExec `!insertmacro PowerShellExecMacro`&lt;br /&gt;
!define PowerShellExecLog `!insertmacro PowerShellExecLogMacro`&lt;br /&gt;
!define PowerShellExecFile `!insertmacro PowerShellExecFileMacro`&lt;br /&gt;
!define PowerShellExecFileLog `!insertmacro PowerShellExecFileLogMacro`&lt;br /&gt;
&lt;br /&gt;
!endif&lt;br /&gt;
&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Version History ==&lt;br /&gt;
; [Update 2014-01-07]&lt;br /&gt;
: Initial version&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:System Related Functions]]&lt;/div&gt;</summary>
		<author><name>CharlesB</name></author>
	</entry>
	<entry>
		<id>https://nsis.sourceforge.io/mediawiki/index.php?title=PowerShell_support&amp;diff=24001</id>
		<title>PowerShell support</title>
		<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=PowerShell_support&amp;diff=24001"/>
		<updated>2014-01-07T20:51:18Z</updated>

		<summary type="html">&lt;p&gt;CharlesB: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{PageAuthor|CharlesB}}&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
These macros simplify PowerShell use in NSIS, and overcome a bug of PowerShell v2, [[http://forums.winamp.com/showthread.php?p=2969465 described here]], and [[http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected reported here]]). &lt;br /&gt;
&lt;br /&gt;
PowerShellExec and PowerShellExecLog respectively the script output on &lt;br /&gt;
the stack and in the log window&lt;br /&gt;
The same goes for PowerShellExecFile and PowerShellExecFileLog, which &lt;br /&gt;
are used to execute a PowerShell script file.&lt;br /&gt;
&lt;br /&gt;
If execution fails, the error level is set to 2.&lt;br /&gt;
&lt;br /&gt;
== How to use ==&lt;br /&gt;
&lt;br /&gt;
Save the script in a file named psexec.nsh, and place it next to your .nsi (or in the NSIS include directory). Then in your script, put an !include psexec.nsh, and call it like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;${PowerShellExec} &amp;quot;echo &#039;hello powershell&#039;&amp;quot;  &lt;br /&gt;
Pop $R1 ;$R1 is &amp;quot;hello powershell&amp;quot;&lt;br /&gt;
&lt;br /&gt;
InitPluginsDir&lt;br /&gt;
SetOutput $PLUGINSDIR\Powershell&lt;br /&gt;
File script.ps1&lt;br /&gt;
${PowerShellExecFileLog} &amp;quot;$PLUGINSDIR\Powershell\script.ps1&amp;quot; &amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In your PS commands, remember to escape the dollar sign by doubling it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;${PowerShellExec} &amp;quot;echo $$ProgramFiles&amp;quot;&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls ==&lt;br /&gt;
&lt;br /&gt;
Be aware that as long as the installer is a 32 bit process, the PowerShell interpreter&lt;br /&gt;
is also in 32 bit. This can cause redirections in filesystem, registry and environment&lt;br /&gt;
variables when running or 64 bit systems (see https://en.wikipedia.org/wiki/WoW64)&lt;br /&gt;
&lt;br /&gt;
Also I found that executing a file directly from $PLUGINSDIR caused errors in script execution, and that saving it in a $PLUGINSDIR subfolder prevented the errors. &lt;br /&gt;
&lt;br /&gt;
== The Script ==&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;&lt;br /&gt;
!ifndef PSEXEC_INCLUDED&lt;br /&gt;
!define PSEXEC_INCLUDED&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecMacro PSCommand&lt;br /&gt;
  InitPluginsDir&lt;br /&gt;
  ;Save command in a temp file&lt;br /&gt;
  Push $R1&lt;br /&gt;
  FileOpen $R1 $PLUGINSDIR\tempfile.ps1 w&lt;br /&gt;
  FileWrite $R1 &amp;quot;${PSCommand}&amp;quot;&lt;br /&gt;
  FileClose $R1&lt;br /&gt;
  Pop $R1&lt;br /&gt;
  &lt;br /&gt;
  !insertmacro PowerShellExecFileMacro &amp;quot;$PLUGINSDIR\tempfile.ps1&amp;quot;&lt;br /&gt;
!macroend&lt;br /&gt;
 &lt;br /&gt;
!macro PowerShellExecLogMacro PSCommand&lt;br /&gt;
  InitPluginsDir&lt;br /&gt;
  ;Save command in a temp file&lt;br /&gt;
  Push $R1&lt;br /&gt;
  FileOpen $R1 $PLUGINSDIR\tempfile.ps1 w&lt;br /&gt;
  FileWrite $R1 &amp;quot;${PSCommand}&amp;quot;&lt;br /&gt;
  FileClose $R1&lt;br /&gt;
  Pop $R1&lt;br /&gt;
  &lt;br /&gt;
  !insertmacro PowerShellExecFileLogMacro &amp;quot;$PLUGINSDIR\tempfile.ps1&amp;quot;&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecFileMacro PSFile&lt;br /&gt;
  !define PSExecID ${__LINE__}&lt;br /&gt;
  Push $R0&lt;br /&gt;
  &lt;br /&gt;
  nsExec::ExecToStack &#039;powershell -inputformat none -ExecutionPolicy RemoteSigned -File &amp;quot;${PSFile}&amp;quot;  &#039;&lt;br /&gt;
&lt;br /&gt;
  Pop $R0 ;return value is first on stack&lt;br /&gt;
  ;script output is second on stack, leave on top of it&lt;br /&gt;
  IntCmp $R0 0 finish_${PSExecID}&lt;br /&gt;
  SetErrorLevel 2&lt;br /&gt;
  &lt;br /&gt;
finish_${PSExecID}:&lt;br /&gt;
  Exch ;now $R0 on top of stack, followed by script output&lt;br /&gt;
  Pop $R0&lt;br /&gt;
  !undef PSExecID&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecFileLogMacro PSFile&lt;br /&gt;
  !define PSExecID ${__LINE__}&lt;br /&gt;
  Push $R0&lt;br /&gt;
  &lt;br /&gt;
  nsExec::ExecToLog &#039;powershell -inputformat none -ExecutionPolicy RemoteSigned -File &amp;quot;${PSFile}&amp;quot;  &#039;&lt;br /&gt;
  Pop $R0 ;return value is on stack&lt;br /&gt;
  IntCmp $R0 0 finish_${PSExecID}&lt;br /&gt;
  SetErrorLevel 2&lt;br /&gt;
  &lt;br /&gt;
finish_${PSExecID}:&lt;br /&gt;
  Pop $R0&lt;br /&gt;
  !undef PSExecID&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!define PowerShellExec `!insertmacro PowerShellExecMacro`&lt;br /&gt;
!define PowerShellExecLog `!insertmacro PowerShellExecLogMacro`&lt;br /&gt;
!define PowerShellExecFile `!insertmacro PowerShellExecFileMacro`&lt;br /&gt;
!define PowerShellExecFileLog `!insertmacro PowerShellExecFileLogMacro`&lt;br /&gt;
&lt;br /&gt;
!endif&lt;br /&gt;
&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Version History ==&lt;br /&gt;
; [Update 2014-01-07]&lt;br /&gt;
: Initial version&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:System Related Functions]]&lt;/div&gt;</summary>
		<author><name>CharlesB</name></author>
	</entry>
	<entry>
		<id>https://nsis.sourceforge.io/mediawiki/index.php?title=PowerShell_support&amp;diff=24000</id>
		<title>PowerShell support</title>
		<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=PowerShell_support&amp;diff=24000"/>
		<updated>2014-01-07T18:30:45Z</updated>

		<summary type="html">&lt;p&gt;CharlesB: fix include&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{PageAuthor|CharlesB}}&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
These macros simplify PowerShell use in NSIS, and overcomes a bug of PowerShell v2, [[http://forums.winamp.com/showthread.php?p=2969465 described here]], and [[http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected reported here]]). &lt;br /&gt;
&lt;br /&gt;
PowerShellExec and PowerShellExecLog respectively the script output on &lt;br /&gt;
the stack and in the log window&lt;br /&gt;
The same goes for PowerShellExecFile and PowerShellExecFileLog, which &lt;br /&gt;
are used to execute a PowerShell script file.&lt;br /&gt;
&lt;br /&gt;
If execution fails, the error level is set to 2.&lt;br /&gt;
&lt;br /&gt;
== How to use ==&lt;br /&gt;
&lt;br /&gt;
Save the script in a file named psexec.nsh, and place it next to your .nsi (or in the NSIS include directory). Then in your script, put an !include psexec.nsh, and call it like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;${PowerShellExec} &amp;quot;echo &#039;hello powershell&#039;&amp;quot;  &lt;br /&gt;
Pop $R1 ;$R1 is &amp;quot;hello powershell&amp;quot;&lt;br /&gt;
&lt;br /&gt;
InitPluginsDir&lt;br /&gt;
SetOutput $PLUGINSDIR\Powershell&lt;br /&gt;
File script.ps1&lt;br /&gt;
${PowerShellExecFileLog} &amp;quot;$PLUGINSDIR\Powershell\script.ps1&amp;quot; &amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In your PS commands, remember to escape the dollar sign by doubling it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;${PowerShellExec} &amp;quot;echo $$ProgramFiles&amp;quot;&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls ==&lt;br /&gt;
&lt;br /&gt;
Be aware that as long as the installer is a 32 bit process, the PowerShell interpreter&lt;br /&gt;
is also in 32 bit. This can cause redirections in filesystem, registry and environment&lt;br /&gt;
variables when running or 64 bit systems (see https://en.wikipedia.org/wiki/WoW64)&lt;br /&gt;
&lt;br /&gt;
Also I found that executing a file directly from $PLUGINSDIR caused errors in script execution, and that saving it in a $PLUGINSDIR subfolder prevented the errors. &lt;br /&gt;
&lt;br /&gt;
== The Script ==&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;&lt;br /&gt;
!ifndef PSEXEC_INCLUDED&lt;br /&gt;
!define PSEXEC_INCLUDED&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecMacro PSCommand&lt;br /&gt;
  InitPluginsDir&lt;br /&gt;
  ;Save command in a temp file&lt;br /&gt;
  Push $R1&lt;br /&gt;
  FileOpen $R1 $PLUGINSDIR\tempfile.ps1 w&lt;br /&gt;
  FileWrite $R1 &amp;quot;${PSCommand}&amp;quot;&lt;br /&gt;
  FileClose $R1&lt;br /&gt;
  Pop $R1&lt;br /&gt;
  &lt;br /&gt;
  !insertmacro PowerShellExecFileMacro &amp;quot;$PLUGINSDIR\tempfile.ps1&amp;quot;&lt;br /&gt;
!macroend&lt;br /&gt;
 &lt;br /&gt;
!macro PowerShellExecLogMacro PSCommand&lt;br /&gt;
  InitPluginsDir&lt;br /&gt;
  ;Save command in a temp file&lt;br /&gt;
  Push $R1&lt;br /&gt;
  FileOpen $R1 $PLUGINSDIR\tempfile.ps1 w&lt;br /&gt;
  FileWrite $R1 &amp;quot;${PSCommand}&amp;quot;&lt;br /&gt;
  FileClose $R1&lt;br /&gt;
  Pop $R1&lt;br /&gt;
  &lt;br /&gt;
  !insertmacro PowerShellExecFileLogMacro &amp;quot;$PLUGINSDIR\tempfile.ps1&amp;quot;&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecFileMacro PSFile&lt;br /&gt;
  !define PSExecID ${__LINE__}&lt;br /&gt;
  Push $R0&lt;br /&gt;
  &lt;br /&gt;
  nsExec::ExecToStack &#039;powershell -inputformat none -ExecutionPolicy RemoteSigned -File &amp;quot;${PSFile}&amp;quot;  &#039;&lt;br /&gt;
&lt;br /&gt;
  Pop $R0 ;return value is first on stack&lt;br /&gt;
  ;script output is second on stack, leave on top of it&lt;br /&gt;
  IntCmp $R0 0 finish_${PSExecID}&lt;br /&gt;
  SetErrorLevel 2&lt;br /&gt;
  &lt;br /&gt;
finish_${PSExecID}:&lt;br /&gt;
  Exch ;now $R0 on top of stack, followed by script output&lt;br /&gt;
  Pop $R0&lt;br /&gt;
  !undef PSExecID&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecFileLogMacro PSFile&lt;br /&gt;
  !define PSExecID ${__LINE__}&lt;br /&gt;
  Push $R0&lt;br /&gt;
  &lt;br /&gt;
  nsExec::ExecToLog &#039;powershell -inputformat none -ExecutionPolicy RemoteSigned -File &amp;quot;${PSFile}&amp;quot;  &#039;&lt;br /&gt;
  Pop $R0 ;return value is on stack&lt;br /&gt;
  IntCmp $R0 0 finish_${PSExecID}&lt;br /&gt;
  SetErrorLevel 2&lt;br /&gt;
  &lt;br /&gt;
finish_${PSExecID}:&lt;br /&gt;
  Pop $R0&lt;br /&gt;
  !undef PSExecID&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!define PowerShellExec `!insertmacro PowerShellExecMacro`&lt;br /&gt;
!define PowerShellExecLog `!insertmacro PowerShellExecLogMacro`&lt;br /&gt;
!define PowerShellExecFile `!insertmacro PowerShellExecFileMacro`&lt;br /&gt;
!define PowerShellExecFileLog `!insertmacro PowerShellExecFileLogMacro`&lt;br /&gt;
&lt;br /&gt;
!endif&lt;br /&gt;
&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Version History ==&lt;br /&gt;
; [Update 2014-01-07]&lt;br /&gt;
: Initial version&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:System Related Functions]]&lt;/div&gt;</summary>
		<author><name>CharlesB</name></author>
	</entry>
	<entry>
		<id>https://nsis.sourceforge.io/mediawiki/index.php?title=Execute_PowerShell_script_or_command&amp;diff=23999</id>
		<title>Execute PowerShell script or command</title>
		<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=Execute_PowerShell_script_or_command&amp;diff=23999"/>
		<updated>2014-01-07T18:16:22Z</updated>

		<summary type="html">&lt;p&gt;CharlesB: moved Execute PowerShell script or command to PowerShell support&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[PowerShell support]]&lt;/div&gt;</summary>
		<author><name>CharlesB</name></author>
	</entry>
	<entry>
		<id>https://nsis.sourceforge.io/mediawiki/index.php?title=PowerShell_support&amp;diff=23998</id>
		<title>PowerShell support</title>
		<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=PowerShell_support&amp;diff=23998"/>
		<updated>2014-01-07T18:16:22Z</updated>

		<summary type="html">&lt;p&gt;CharlesB: moved Execute PowerShell script or command to PowerShell support&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{PageAuthor|CharlesB}}&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
These macros simplify PowerShell use in NSIS, and overcomes a bug of PowerShell v2, [[http://forums.winamp.com/showthread.php?p=2969465 described here]], and [[http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected reported here]]). &lt;br /&gt;
&lt;br /&gt;
PowerShellExec and PowerShellExecLog respectively the script output on &lt;br /&gt;
the stack and in the log window&lt;br /&gt;
The same goes for PowerShellExecFile and PowerShellExecFileLog, which &lt;br /&gt;
are used to execute a PowerShell script file.&lt;br /&gt;
&lt;br /&gt;
If execution fails, the error level is set to 2.&lt;br /&gt;
&lt;br /&gt;
== How to use ==&lt;br /&gt;
&lt;br /&gt;
Save the script in a file named psexec.nsh, and place it next to your .nsi (or in the NSIS include directory). Then in your script, put an !include psexec.nsh, and call it like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;${PowerShellExec} &amp;quot;echo &#039;hello powershell&#039;&amp;quot;  &lt;br /&gt;
Pop $R1 ;$R1 is &amp;quot;hello powershell&amp;quot;&lt;br /&gt;
&lt;br /&gt;
InitPluginsDir&lt;br /&gt;
SetOutput $PLUGINSDIR\Powershell&lt;br /&gt;
File script.ps1&lt;br /&gt;
${PowerShellExecFileLog} &amp;quot;$PLUGINSDIR\Powershell\script.ps1&amp;quot; &amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In your PS commands, remember to escape the dollar sign by doubling it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;${PowerShellExec} &amp;quot;echo $$ProgramFiles&amp;quot;&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls ==&lt;br /&gt;
&lt;br /&gt;
Be aware that as long as the installer is a 32 bit process, the PowerShell interpreter&lt;br /&gt;
is also in 32 bit. This can cause redirections in filesystem, registry and environment&lt;br /&gt;
variables when running or 64 bit systems (see https://en.wikipedia.org/wiki/WoW64)&lt;br /&gt;
&lt;br /&gt;
Also I found that executing a file directly from $PLUGINSDIR caused errors in script execution, and that saving it in a $PLUGINSDIR subfolder prevented the errors. &lt;br /&gt;
&lt;br /&gt;
== The Script ==&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;&lt;br /&gt;
!ifndef PSEXEC_INCLUDED&lt;br /&gt;
!define PSEXEC_INCLUDED&lt;br /&gt;
&lt;br /&gt;
!include nsexec.nsh&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecMacro PSCommand&lt;br /&gt;
  InitPluginsDir&lt;br /&gt;
  ;Save command in a temp file&lt;br /&gt;
  Push $R1&lt;br /&gt;
  FileOpen $R1 $PLUGINSDIR\tempfile.ps1 w&lt;br /&gt;
  FileWrite $R1 &amp;quot;${PSCommand}&amp;quot;&lt;br /&gt;
  FileClose $R1&lt;br /&gt;
  Pop $R1&lt;br /&gt;
  &lt;br /&gt;
  !insertmacro PowerShellExecFileMacro &amp;quot;$PLUGINSDIR\tempfile.ps1&amp;quot;&lt;br /&gt;
!macroend&lt;br /&gt;
 &lt;br /&gt;
!macro PowerShellExecLogMacro PSCommand&lt;br /&gt;
  InitPluginsDir&lt;br /&gt;
  ;Save command in a temp file&lt;br /&gt;
  Push $R1&lt;br /&gt;
  FileOpen $R1 $PLUGINSDIR\tempfile.ps1 w&lt;br /&gt;
  FileWrite $R1 &amp;quot;${PSCommand}&amp;quot;&lt;br /&gt;
  FileClose $R1&lt;br /&gt;
  Pop $R1&lt;br /&gt;
  &lt;br /&gt;
  !insertmacro PowerShellExecFileLogMacro &amp;quot;$PLUGINSDIR\tempfile.ps1&amp;quot;&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecFileMacro PSFile&lt;br /&gt;
  !define PSExecID ${__LINE__}&lt;br /&gt;
  Push $R0&lt;br /&gt;
  &lt;br /&gt;
  nsExec::ExecToStack &#039;powershell -inputformat none -ExecutionPolicy RemoteSigned -File &amp;quot;${PSFile}&amp;quot;  &#039;&lt;br /&gt;
&lt;br /&gt;
  Pop $R0 ;return value is first on stack&lt;br /&gt;
  ;script output is second on stack, leave on top of it&lt;br /&gt;
  IntCmp $R0 0 finish_${PSExecID}&lt;br /&gt;
  SetErrorLevel 2&lt;br /&gt;
  &lt;br /&gt;
finish_${PSExecID}:&lt;br /&gt;
  Exch ;now $R0 on top of stack, followed by script output&lt;br /&gt;
  Pop $R0&lt;br /&gt;
  !undef PSExecID&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecFileLogMacro PSFile&lt;br /&gt;
  !define PSExecID ${__LINE__}&lt;br /&gt;
  Push $R0&lt;br /&gt;
  &lt;br /&gt;
  nsExec::ExecToLog &#039;powershell -inputformat none -ExecutionPolicy RemoteSigned -File &amp;quot;${PSFile}&amp;quot;  &#039;&lt;br /&gt;
  Pop $R0 ;return value is on stack&lt;br /&gt;
  IntCmp $R0 0 finish_${PSExecID}&lt;br /&gt;
  SetErrorLevel 2&lt;br /&gt;
  &lt;br /&gt;
finish_${PSExecID}:&lt;br /&gt;
  Pop $R0&lt;br /&gt;
  !undef PSExecID&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!define PowerShellExec `!insertmacro PowerShellExecMacro`&lt;br /&gt;
!define PowerShellExecLog `!insertmacro PowerShellExecLogMacro`&lt;br /&gt;
!define PowerShellExecFile `!insertmacro PowerShellExecFileMacro`&lt;br /&gt;
!define PowerShellExecFileLog `!insertmacro PowerShellExecFileLogMacro`&lt;br /&gt;
&lt;br /&gt;
!endif&lt;br /&gt;
&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Version History ==&lt;br /&gt;
; [Update 2014-01-07]&lt;br /&gt;
: Initial version&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:System Related Functions]]&lt;/div&gt;</summary>
		<author><name>CharlesB</name></author>
	</entry>
	<entry>
		<id>https://nsis.sourceforge.io/mediawiki/index.php?title=PowerShell_support&amp;diff=23997</id>
		<title>PowerShell support</title>
		<link rel="alternate" type="text/html" href="https://nsis.sourceforge.io/mediawiki/index.php?title=PowerShell_support&amp;diff=23997"/>
		<updated>2014-01-07T18:13:35Z</updated>

		<summary type="html">&lt;p&gt;CharlesB: Initial version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{PageAuthor|CharlesB}}&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
These macros simplify PowerShell use in NSIS, and overcomes a bug of PowerShell v2, [[http://forums.winamp.com/showthread.php?p=2969465 described here]], and [[http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected reported here]]). &lt;br /&gt;
&lt;br /&gt;
PowerShellExec and PowerShellExecLog respectively the script output on &lt;br /&gt;
the stack and in the log window&lt;br /&gt;
The same goes for PowerShellExecFile and PowerShellExecFileLog, which &lt;br /&gt;
are used to execute a PowerShell script file.&lt;br /&gt;
&lt;br /&gt;
If execution fails, the error level is set to 2.&lt;br /&gt;
&lt;br /&gt;
== How to use ==&lt;br /&gt;
&lt;br /&gt;
Save the script in a file named psexec.nsh, and place it next to your .nsi (or in the NSIS include directory). Then in your script, put an !include psexec.nsh, and call it like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;${PowerShellExec} &amp;quot;echo &#039;hello powershell&#039;&amp;quot;  &lt;br /&gt;
Pop $R1 ;$R1 is &amp;quot;hello powershell&amp;quot;&lt;br /&gt;
&lt;br /&gt;
InitPluginsDir&lt;br /&gt;
SetOutput $PLUGINSDIR\Powershell&lt;br /&gt;
File script.ps1&lt;br /&gt;
${PowerShellExecFileLog} &amp;quot;$PLUGINSDIR\Powershell\script.ps1&amp;quot; &amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In your PS commands, remember to escape the dollar sign by doubling it: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;${PowerShellExec} &amp;quot;echo $$ProgramFiles&amp;quot;&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Pitfalls ==&lt;br /&gt;
&lt;br /&gt;
Be aware that as long as the installer is a 32 bit process, the PowerShell interpreter&lt;br /&gt;
is also in 32 bit. This can cause redirections in filesystem, registry and environment&lt;br /&gt;
variables when running or 64 bit systems (see https://en.wikipedia.org/wiki/WoW64)&lt;br /&gt;
&lt;br /&gt;
Also I found that executing a file directly from $PLUGINSDIR caused errors in script execution, and that saving it in a $PLUGINSDIR subfolder prevented the errors. &lt;br /&gt;
&lt;br /&gt;
== The Script ==&lt;br /&gt;
&amp;lt;highlight-nsis&amp;gt;&lt;br /&gt;
!ifndef PSEXEC_INCLUDED&lt;br /&gt;
!define PSEXEC_INCLUDED&lt;br /&gt;
&lt;br /&gt;
!include nsexec.nsh&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecMacro PSCommand&lt;br /&gt;
  InitPluginsDir&lt;br /&gt;
  ;Save command in a temp file&lt;br /&gt;
  Push $R1&lt;br /&gt;
  FileOpen $R1 $PLUGINSDIR\tempfile.ps1 w&lt;br /&gt;
  FileWrite $R1 &amp;quot;${PSCommand}&amp;quot;&lt;br /&gt;
  FileClose $R1&lt;br /&gt;
  Pop $R1&lt;br /&gt;
  &lt;br /&gt;
  !insertmacro PowerShellExecFileMacro &amp;quot;$PLUGINSDIR\tempfile.ps1&amp;quot;&lt;br /&gt;
!macroend&lt;br /&gt;
 &lt;br /&gt;
!macro PowerShellExecLogMacro PSCommand&lt;br /&gt;
  InitPluginsDir&lt;br /&gt;
  ;Save command in a temp file&lt;br /&gt;
  Push $R1&lt;br /&gt;
  FileOpen $R1 $PLUGINSDIR\tempfile.ps1 w&lt;br /&gt;
  FileWrite $R1 &amp;quot;${PSCommand}&amp;quot;&lt;br /&gt;
  FileClose $R1&lt;br /&gt;
  Pop $R1&lt;br /&gt;
  &lt;br /&gt;
  !insertmacro PowerShellExecFileLogMacro &amp;quot;$PLUGINSDIR\tempfile.ps1&amp;quot;&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecFileMacro PSFile&lt;br /&gt;
  !define PSExecID ${__LINE__}&lt;br /&gt;
  Push $R0&lt;br /&gt;
  &lt;br /&gt;
  nsExec::ExecToStack &#039;powershell -inputformat none -ExecutionPolicy RemoteSigned -File &amp;quot;${PSFile}&amp;quot;  &#039;&lt;br /&gt;
&lt;br /&gt;
  Pop $R0 ;return value is first on stack&lt;br /&gt;
  ;script output is second on stack, leave on top of it&lt;br /&gt;
  IntCmp $R0 0 finish_${PSExecID}&lt;br /&gt;
  SetErrorLevel 2&lt;br /&gt;
  &lt;br /&gt;
finish_${PSExecID}:&lt;br /&gt;
  Exch ;now $R0 on top of stack, followed by script output&lt;br /&gt;
  Pop $R0&lt;br /&gt;
  !undef PSExecID&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!macro PowerShellExecFileLogMacro PSFile&lt;br /&gt;
  !define PSExecID ${__LINE__}&lt;br /&gt;
  Push $R0&lt;br /&gt;
  &lt;br /&gt;
  nsExec::ExecToLog &#039;powershell -inputformat none -ExecutionPolicy RemoteSigned -File &amp;quot;${PSFile}&amp;quot;  &#039;&lt;br /&gt;
  Pop $R0 ;return value is on stack&lt;br /&gt;
  IntCmp $R0 0 finish_${PSExecID}&lt;br /&gt;
  SetErrorLevel 2&lt;br /&gt;
  &lt;br /&gt;
finish_${PSExecID}:&lt;br /&gt;
  Pop $R0&lt;br /&gt;
  !undef PSExecID&lt;br /&gt;
!macroend&lt;br /&gt;
&lt;br /&gt;
!define PowerShellExec `!insertmacro PowerShellExecMacro`&lt;br /&gt;
!define PowerShellExecLog `!insertmacro PowerShellExecLogMacro`&lt;br /&gt;
!define PowerShellExecFile `!insertmacro PowerShellExecFileMacro`&lt;br /&gt;
!define PowerShellExecFileLog `!insertmacro PowerShellExecFileLogMacro`&lt;br /&gt;
&lt;br /&gt;
!endif&lt;br /&gt;
&amp;lt;/highlight-nsis&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Version History ==&lt;br /&gt;
; [Update 2014-01-07]&lt;br /&gt;
: Initial version&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:System Related Functions]]&lt;/div&gt;</summary>
		<author><name>CharlesB</name></author>
	</entry>
</feed>