Shoutbox

KILL AN APP - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: KILL AN APP (/showthread.php?tid=61972)

KILL AN APP by novolo on 06-29-2006 at 02:30 AM

hi,  i made script to run applications through commands..   now,  i was wondering,  is there a way to kill an external application through sript?


RE: KILL AN APP by ShawnZ on 06-29-2006 at 02:40 AM

new ActiveXObject("WScript.Shell").Run("taskkill /f /im" + IMAGE_NAME)


RE: KILL AN APP by ddunk on 06-29-2006 at 02:45 AM

quote:
Originally posted by ShawnZ
new ActiveXObject("WScript.Shell").Run("taskkill /f /im" + IMAGE_NAME)
taskkill isn't in XP Home, silly boy.
RE: KILL AN APP by cooldude_i06 on 06-29-2006 at 04:57 AM

you can include taskkill.exe with the script cant you?


RE: KILL AN APP by matty on 06-29-2006 at 05:02 AM

quote:
Originally posted by cooldude_i06
you can include taskkill.exe with the script cant you?
No it wont run on a Windows XP Home installation.
RE: KILL AN APP by ddunk on 06-29-2006 at 05:05 AM

quote:
Originally posted by Matty
quote:
Originally posted by cooldude_i06
you can include taskkill.exe with the script cant you?
No it wont run on a Windows XP Home installation.
Actually, it does.
E:\Program Files\mirc\download>taskkill.exe /im editplus.exe
SUCCESS: The process "editplus.exe" with PID 1804 has been terminated.
RE: KILL AN APP by matty on 06-29-2006 at 05:11 AM

quote:
Originally posted by Ddunk
quote:
Originally posted by Matty
quote:
Originally posted by cooldude_i06
you can include taskkill.exe with the script cant you?
No it wont run on a Windows XP Home installation.
Actually, it does.
E:\Program Files\mirc\download>taskkill.exe /im editplus.exe
SUCCESS: The process "editplus.exe" with PID 1804 has been terminated.
Hmmm thats the gay cause when I last tried it, it didn't work. Anyways you can do this with the API all you need to know is the handle of the window I will post code for it later.
RE: KILL AN APP by ShawnZ on 06-29-2006 at 05:16 AM

quote:
Originally posted by Matty
Hmmm thats the gay cause when I last tried it, it didn't work.

oh yeah? what error?
RE: KILL AN APP by CookieRevised on 06-29-2006 at 11:48 AM

quote:
Originally posted by ShawnZ
new ActiveXObject("WScript.Shell").Run("taskkill /f /im" + IMAGE_NAME)
crappy method to (and the need to) include an external app to kill a task... Use the Windows APIs instead.
RE: KILL AN APP by novolo on 06-29-2006 at 01:51 PM

could anyone post the script to kill an app with the windows api?


RE: KILL AN APP by matty on 06-29-2006 at 02:21 PM

quote:
Originally posted by novolo
could anyone post the script to kill an app with the windows api?
If we do that you wont ever learn. Look up GetWindowThreadProcessId
RE: KILL AN APP by novolo on 06-30-2006 at 12:13 AM

i've just entered that link,  and sorry to  say  but i don't understand anything...
i'm not a programmer,    could anyone just give me the code to kill an app?   its only one line.. :P


RE: KILL AN APP by CookieRevised on 06-30-2006 at 04:45 PM

Proper code to kill an app is not just one code, it will contain many lines of code though.


RE: KILL AN APP by novolo on 06-30-2006 at 06:02 PM

ohh,  ok,    any chance anyone knows how to do it?


RE: KILL AN APP by matty on 06-30-2006 at 06:04 PM

quote:
Originally posted by novolo
ohh,  ok,    any chance anyone knows how to do it?
It is not that we don't know how to do it, its actually a bit complicated. There are many different ways of doing it for instance you can find the handle of the window, from that get the PID then send terminate process command to force it to close. Not the best way cause it doesn't provide the app enough time to save information.
RE: KILL AN APP by ShawnZ on 06-30-2006 at 06:53 PM

it'd be something like

Interop.Call("user32.dll", "SendMessageA", WindowHandle, 274, 61536, 0);


RE: KILL AN APP by matty on 06-30-2006 at 11:43 PM

code:
function ShutdownApp(hWnd){
    var lProcessID = Interop.Allocate(4);
    var lProcess = Interop.Allocate(4);
   
    Interop.Call('user32', 'GetWindowThreadProcessId', hWnd, lProcessID);
    lProcess.WriteDWORD(0, Interop.Call('kernel32', 'OpenProcess', 1, false, lProcessID.ReadDWORD(0)));
    Interop.Call('kernel32', 'TerminateProcess', lProcess.ReadDWORD(0), 1);
    Interop.Call('kernel32', 'CloseHandle', lProcess.ReadDWORD(0));
}

This was shown to me by Cook but I am too lazy to convert it to a Plus! script.

http://www.andreavb.com/tip020021.html
RE: KILL AN APP by novolo on 07-01-2006 at 12:17 AM

any chance that this could be coded in plus script?


RE: KILL AN APP by dylan! on 07-01-2006 at 12:22 AM

quote:
Originally posted by novolo
any chance that this could be coded in plus script?
if your not a coder then what good does this do you?
and what good would it do you if it was in plus script?:|
if your coding a plus script and all you need is this part... how are you going to do the rest of it?
RE: KILL AN APP by novolo on 07-01-2006 at 01:55 AM

ok ok ,  i need this part for a script i made to run applications remotely...    the thing is  i can run applications remotely from a selected email  but i dont know how to kill them...     now  if there's someone out there who is willing to help me rather than ask if i dont know or why am i doing this,  or that i should't ask if i'm not a coder,  you'r welcome..


RE: KILL AN APP by cloudhunter on 07-01-2006 at 02:13 AM

I found it pays to experiment, and do a google seach every once in a while. They were merely commenting on your seeming lack of knowledge to do with scripting.

The script posted there can shut down an app if you know the processes hWnd.

Cloudy


RE: KILL AN APP by novolo on 07-01-2006 at 02:29 AM

so,  that function will work as it is in plus script...
now,   in the script documentation,  does it say whats the hWnd and how to know what app has wich hWnd?


RE: KILL AN APP by cloudhunter on 07-01-2006 at 02:55 AM

Not meaning to get at you, but use your eyes for once. All the information is out there, find it.

Cloudy


RE: RE: KILL AN APP by CookieRevised on 07-02-2006 at 03:37 AM

quote:
Originally posted by novolo
so,  that function will work as it is in plus script...
The example shown is not tested, but gives you an idea of what would be involved.

Also, the given VB example in that link posted by Matty (which I gave to him among other links) is a nice example but the code contains a few useless things and also lacks the part where you actually try to close the application in a not forcefull way as you should always do that first.

quote:
Originally posted by novolo
now,   in the script documentation,  does it say whats the hWnd and how to know what app has wich hWnd?
No, as that should be common programming knowledge. The Scripting Documentation is meant to give info on the Messenger Plus! objects and stuff, it isn't a general "how do I program" tutorial. A Window handle (hWnd) is unique for each window, an application can have many windows, or even no windows at all. And these window handles are not fixed numbers, they are assigned and removed on the fly and thus change each time.

To know the window handle for a given process name you need a bunch of other code. Note that different processes can have the same name, so you should loop them all. And also, note that a single process/application can contain many windows, and you will never know what window is the main window. So in fact you even need to get all window handles for a given module and process them all (in order to let the application close properly first, before forcing the process to close).
RE: KILL AN APP by novolo on 07-02-2006 at 05:22 PM

oh:( ,     then i think i can't do this..   i thought that the hWnd was always the same for an app,   for example,  my script opens the windows media player,  or performs a scan with norton antivirus,     so i thought that if i found out what's their hWnd,   i could always kill those apps...     
but now, as you say,  the hWnd is different every-time they run,  then is far more complicated than i thought


RE: KILL AN APP by matty on 07-02-2006 at 06:55 PM

quote:
Originally posted by CookieRevised
The example shown is not tested, but gives you an idea of what would be involved.
Actually Cook it is :P