rumovoice
3rd April 2012 11:49 UTC
Can't understand how stack works
I've written following function:
Function KillMyProcess
; Change current directory to temp
; to prevent creation of TempWmicBatchFile.bat
Push $OUTDIR
StrCpy $OUTDIR $TEMP
nsexec::ExecToLog "wmic process where name='MyApp.exe' delete"
Pop $OUTDIR
FunctionEnd
As far as I know $OUTDIR should not change after this function is called, but it equals to 0 instead. I tried to add debug message boxes. Looks like everything goes fine until Pop is called which just sets $OUTDIR value to zero. Why is that?
rumovoice
3rd April 2012 12:34 UTC
And also I've discovered that changing $OUTDIR on a page before instfiles does not help. Looks like it do not change current directory before instfiles.
pengyou
3rd April 2012 13:11 UTC
From the documentation for the nsExec plugin:
If nsExec is unable to execute the process, it will return "error" on the top of the stack, if the process timed out it will return "timeout", else it will return the return code from the executed process.
So your code is putting the return value from nsExec into $OUTDIR and leaving the original value still on the stack. You need to use another Pop command to retrieve the $OUTDIR value you saved on the stack.
There is a wiki page that has some information about how the stack works:
http://nsis.sourceforge.net/Pop,_Pus...h..._The_Stack
rumovoice
3rd April 2012 14:13 UTC
Thank you