我正在尝试在 NSIS 中运行 PowerShell。当我运行 NSIS 脚本时:
!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
当它执行到“Import-Module ServerManager”时,PowerShell 已启动(可以在 TaskManager 进程中看到)。但 nsExecTest.exe 悬而未决。
我用谷歌搜索了这个问题,并找到了 Java 的解决方法。 https://blogs.oracle.com/vaibhav/entry/not_as_easy_as_we
有人对 NSIS 中的这个问题有想法吗?
更新:我简化了我的测试脚本。
!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