问题
I'm using the macro defined here, on Windows 7, however it always returns 1.
This is how I'm calling it:
!insertmacro FindProc $processFound "MyApp.exe"
MessageBox MB_OK $processFound
IntCmp $processFound ${FindProc_FOUND} +1 +3 +3
MessageBox MB_ICONEXCLAMATION|MB_OK "Please close the app before running this setup." /SD IDOK
Abort
This seems fairly simple compared to messing around with WMI, and the FindProcDLL method listed on the same page doesn't work anymore (even the NSIS Unicode version). So why would this method always return 1? I've separately verified that
tasklist /nh /fi "IMAGENAME eq MyApp.exe" | find /i "MyApp.exe"
returns 1 and 0 depending on whether the app is running or not.
Update: I've used ExecWait with the same result.
Update 2 : Tried using nsProcess from here, as below -
nsProcess::_FindProcess "myprogram.exe" $R0
MessageBox MB_OK $R0
This always shows up as blank. I have not declared $R0 anywhere else. Is there a syntax error somewhere, or is this also not working on Windows 7?
回答1:
You could try something like this.
FindProcDLL::FindProc "MyApp.exe"
${if} $R0 == 1
MessageBox MB_ICONEXCLAMATION|MB_OK "Killing process now." /SD IDOK
KillProcDLL::KillProc "MyApp.exe"
${EndIf}
回答2:
Hat tip to Anders - I forgot to Pop the result of the function call. The code now works, and looks like this:
nsProcess::_FindProcess "UID.EnrolmentClient.exe" $R0
Pop $0
StrCmp $0 "0" +1 +3
MessageBox MB_ICONEXCLAMATION|MB_OK "Please close the application before running this setup." /SD IDOK
Abort
来源:https://stackoverflow.com/questions/8472502/nsis-findproc-always-returns-1