How to detect a running application in Windows?
Posted by neilvp (neilvp), 24 April 2006Guru Graham
In one of my TCL scripts I output the result to Notepad using exec. The problem is my colleagues find this script so useful and use it so often at times that they find themselves with multiple instances of notepad open.
Is there a way I can detect that notepad (or any other Windows app) is already running and then either shut that one down first (if so how?) or 'over write' it rather than open another instance?
Or should I just tell my colleagues not to be so lazy?
Posted by admin (Graham Ellis), 24 April 2006That's a good one, Neil. I'm training a load of supergeeks today and I threw the question to them over coffee ... they agreed it's a good one too. Which doesn't help you!
I'll be home / back to my Tcl library briefly on Wednesday evening - I'll have a look then if that's not too late? It's probably a question of getting into the Windows registry and reading from there so I'm likely to be on thin ice.
Posted by neilvp (neilvp), 24 April 2006Stumped even the SuperGeeks, wow !
Wednesday or Thursday is fine by me. The problem does not stop the script from working and is a 'nice to have' rather than an absolutely necessary bit of code. (Though it would be useful to know.)
Many thanks Graham, your help and support are very much appreciated.
Posted by admin (Graham Ellis), 25 April 2006I had an unexpected chance to do some researching on this last night - no single all-in-one-place answer but I came across:
1. The registry command in Tcl allowing you to talk to the windows registry:
2. Structure for Notepad (setups at least) in the registry
3. A sample program (in Perl, sorry) that checks what programs are running on what computer ... see especially the code towards the end
An interesting challenge to put all of these together!
Posted by neilvp (neilvp), 25 April 2006And I thought it such an innocent little question!
Thanks for these pointers, this should give me enough to go on.
I have also had a response from the ActiveState forum where the suggestion is to look at the use of TWAPI. See http://wiki.tcl.tk/9886.
There is a further suggestion that the process ID returned by exec be written to file for later referal - so I know which processes to kill if the script is re-run. Will this work? Is the process ID a Windows value and therefore persistent or unique to the TCL app?
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho