Skip to content
⌘ NSIS Forum Archive

Get actual error code if ExecWait fails?

2 posts

alexmitev#

Get actual error code if ExecWait fails?

Hello,
I am interested in getting the actual Windows error code if ExecWait fails. In the docs it is said "ExecWait sets the error flag if an error occurs". As far as I can see, the error flag has 2 values: set and unset, and I need the Windows error code.
If I call GetLastError using System, will it returned the actual Windows error code that ExecWait triggered?
Regards,
Alex
Anders#
No you cannot call GetLastError with the system plugin because the last error can change inside the system plugin code.

You must call CreateProcess yourself:
!include LogicLib.nsh
Section 
!if "${NSIS_PTR_SIZE}" <= 4
System::Call '*(i,i,i,i)i.r0'
System::Alloc 68
pop $4
System::Call "*$4(i 68)"
StrCpy $1 '"explorer.exe" /e,"$startmenu"'
System::Call 'kernel32::CreateProcess(i0,tr1,i0,i0,i0,i 0,i0,i0,ir4,ir0)i.r3?e' ;?e pushes GetLastError result on the stack
Pop $5
DetailPrint Return=$3,GetLastError=$5
System::Free $4
${If} $3 <> 0
    System::Call "*$0(i.r3,i.r4)"
    System::Call 'kernel32::WaitForSingleObject(i $3, i -1)'
    System::Call 'kernel32::CloseHandle(i $3)'
    System::Call 'kernel32::CloseHandle(i $4)'
${EndIf}
System::Free $0
!endif
SectionEnd