Archive: Check if a program is running before you try to un-install it.


What kind of code do I need to check if a program is running before you try to un-install it?


From Documentation (http://genghis.winamp.com/~deadbeef/free/nsis/makensis.htm):

FindWindow close|closeinstant|prompt|goto:label windowclass [messageboxtext]
Checks for a window whose class name is 'windowclass'. If the window is found, the action is based on what 'mode' is set to.
If mode is 'close', this command will attempt to close the window using WM_CLOSE for up to 8 seconds.
If mode is 'closeinstant', this command will send a WM_CLOSE message to the window and continue.
If mode is 'prompt', this command will prompt the user with 'messageboxtext' until the window is closed manually.
If mode is 'goto:label', FindWindow will Goto label.

FindWindowByTitle close|closeinstant|prompt|goto:label windowtitle [messageboxtext]
Acts like FindWindow, only searches for a window based on title instead of class.


Or is it examples you are looking for?
/Anders


If that is possible...

e.g. I want to check if program.exe is running.


hi,

yes, findwindow(bytitle) is what you are looking for

cu yzo


So, does this 'class' stay the same for the particular program? Is it user-definable? How would one find out class a program has?

Forgive me, I know nothing about classes.


hi,

it can stay the same, but it mustn't, that depends on the programmer.

it is not user definable

either you know the classname (because it is documented (like the winamp class 'Winamp v1.x')) or you will have to look it up with a proccess tool (WinSight or something).

cu yzo


hi again ;)

after your post i thought to quick 'n dirty write a small tool for looking up a classname, but a search on the web brought up a pretty nice one, so here is the link:

http://www.torry.net/apps/utilities/.../tdwininfo.zip

cu yzo


Thanks yzo!


But can somebody give me an example code? I don't quite get it, you know.

I want to check if my program, CYBERsex.exe is running. And if it is running then I want to promt the user to close it or to abort the uninstall.


hi,

try it like this:

Function CloseWindow
FindWindow(ByTitle) GoTo:lbl_found windowclass(or_title)

GoTo lbl_end

lbl_found:
MessageBox MB_YESNO 'Close App?' ID_NO lbl_abort
FindWindow(ByTitle) close windowclass(or_title)
GoTo lbl_end

lbl_abort:
Abort 'Install Canceled'

lbl_end:
FunctionEnd

i hope it helps

cu yzo


I'm not home right now, but I'll try it ASAP (probably tomorrow).

Thanks for your input! :)


This CYBERsex thing sounds interesting...:)...is it just an example?


CYBERsex is real! ;) Juct click the link in my signature an you'll know all about it. :D