Archive: If app is running (extended)


If app is running (extended)
I know that i can detect my app useing FindProc and kill by KillProc plugins. But i want to make following: make simple dialog to colse my application. My app uses /quit key to exit.


sample of what i want to see:
1)FindProc find my app
2)tell "app is running" "close?" YES|NO
3)If YES try to colse it useing "app.exe /quit" key or KillProc. For "/quit" key i think plugin must detect full path to "*.exe", don't know is it possible?
4)If NO go to 1'st page of installer
5)FindProc don't find my app => goto 1'st page of installer


any suggestions? or samples?

Section /o      $(ITEM_Closeif) Closeif

FindProcDLL::FindProc "app.exe"
StrCmp $R0 1 found notfound

found:
MessageBox MB_YESNO $(infobox) IDYES true IDNO ;done

true:
KillProcDLL::KillProc "app.exe"
Sleep 2000

; Goto done:

notfound:
;MessageBox MB_OK "App not running." IDOK ;done
;done:

SectionEnd

-> Warning:
According to MSDN (MicroSoft Developers Network):

The TerminateProcess function is used to unconditionally cause a process to exit. Use it only in extreme circumstances. The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess.

So use this DLL carefully as your LAST and EXTREME option :)

KillProc as a first step - it's like a tooth removing on any pain.. Current data will be lost, application files (exe, dll and opened i/o files) may stay marked in system as "in use" - possible problems with deletion without reboot.. WM_CLOSE for a non-dos apps is a good idea as a first step :)


My app doesnt read or write anything(system monitor) thats why I can Kill it with no problem.


You should be using WM_CLOSE rather than the KillProc dll. Like Takhir says, you should only use KillProc dll as a last resort. You should use SendMessage ... first, then check if the program is running and then use KillProc if necessary.

-Stu