I am trying to run PowerShell in NSIS. when I run the NSIS script:
!include "x64.nsh"
Name "nsExec Test"
OutFile "nsExecTest.exe"
ShowInstDetails show
Section "Output to variable"
nsExec::ExecToStack 'powershell -Command "& {Import-Module }" ServerManager'
Pop $0 # return value/error/timeout
Pop $1 # printed text, up to ${NSIS_MAX_STRLEN}
DetailPrint '"ImportModules" printed: $1'
DetailPrint " Return value: $0"
nsExec::ExecToStack 'powershell -Command "& {Get-WindowsFeature}" Desktop-Experience'
Pop $0 # return value/error/timeout
Pop $1 # printed text, up to ${NSIS_MAX_STRLEN}
DetailPrint '"GetWindowsFeature" printed: $1'
DetailPrint " Return value: $0"
SectionEnd
When it executed to "Import-Module ServerManager", The PowerShell was started up(It can be seen in TaskManager processes). But nsExecTest.exe was hanging over.
I have googled this problem, and found a workaround for Java. https://blogs.oracle.com/vaibhav/entry/not_as_easy_as_we
Anyone has ideas for this problem in NSIS?
Updated: I simplify my test script.
!include "x64.nsh"
Name "nsExec Test"
OutFile "nsExecTest.exe"
ShowInstDetails show
Section "Output to variable"
${If} ${RunningX64}
${DisableX64FSRedirection}
nsExec::ExecToStack 'powershell.exe "& "Import-Module ServerManager"'
Pop $0 # return value/error/timeout
Pop $1 # printed text, up to ${NSIS_MAX_STRLEN}
DetailPrint '"ImportModules" printed: $1'
DetailPrint " Return value: $0"
DetailPrint ""
${EnableX64FSRedirection}
${Else}
${EndIf}
SectionEnd