NSIS- FindProc always returns 1

时光总嘲笑我的痴心妄想 提交于 2020-02-08 07:41:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!