NSIS:获取 ExecShell 的 return 代码

NSIS: Get return code of ExecShell

我必须使用ExecShell,因为我的主程序只有用户权限,而该程序中调用的exe文件需要管理员权限。

 RequestExecutionLevel user  

 ExecShell "open" "file.exe" SW_HIDE

我想获取 return 代码,我尝试 pop [=13=], pop ,但我总是得到零。另外,如果文件不成功。 我相信 pop [=14=] 不会等待 ExecShell 命令,但我不能使用 ExecWait 因为需要管理员权限。我怎样才能得到真正的 return 代码?

ExecShell不报错码,因为没有等待进程

如果您想要退出代码,您必须手动调用 ShellExecuteEx

!include LogicLib.nsh
!include WinCore.nsh

!ifndef SEE_MASK_NOCLOSEPROCESS
!define SEE_MASK_NOCLOSEPROCESS 0x00000040
!endif

Section
StrCpy  "Calc.exe" ; File to execute
System::Call '*(&l4, i ${SEE_MASK_NOCLOSEPROCESS}, p$HWNDPARENT, p0, tr1, p0, p0, p5, p0, p0, p0, p0, p0, p0, p)p.r1'
System::Call 'SHELL32::ShellExecuteEx(t)i.r0 (pr1)' ; (t) is a hint for A/W detection
${If} [=10=] <> 0
    System::Call '*(i, i, p, p, p, p, p, p, p, p, p, p, p, p, p.r0)'
    System::Call 'KERNEL32::WaitForSingleObject(p r0, i ${INFINITE})'
    System::Call 'KERNEL32::GetExitCodeProcess(p r0 s,*i.r0)'
    System::Call 'KERNEL32::CloseHandle(p s)'
    DetailPrint ExitCode=[=10=]
${EndIf}
System::Free 
SectionEnd