0

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?

Rex
  • 801
  • 1
  • 17
  • 26
  • The top two zip files on the FindProcDLL page works fine for me with the official 2.46... – Anders Dec 12 '11 at 18:32
  • On Windows 7? I've tried both the official NSIS and the Unicode version, (including the unicode version of the plugin) and none of them work. – Rex Dec 13 '11 at 04:23
  • 1
    That nsProcess syntax has to be wrong, you cannot receive data in a register like that, remove the var and try a pop after the call (See nsProcess.nsh) – Anders Dec 14 '11 at 16:36

2 Answers2

0

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}
0

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
Rex
  • 801
  • 1
  • 17
  • 26