If you want to kill a process on a remote Win32 system, then odds are that you'll want to handle killing things like services that refuse to shut down nicely. There is no Win32 API that lets you kill a service. There is a hack (pushed by Microsoft) of attaching to the process like you were a debugger and adding a thread to it that gets a memory access violation. It might be possible to even do that from Perl, but not remotely.
So first you need your "kill" program (you can get one from Microsoft if you are good at searching -- sorry, I don't have a link handy). Then you just copy your kill program to the remote system (I assume I don't have to explain how to do that). Then you can use Perl to tell the remote system to run your kill program.
Using "Win32 remote run" in Super Search I came up with Using WMI for create a remote Process on Win32 which should let you do that. Though I've never used it as we always installed RemoteCmd from the WinNT Resource Kit on the systems we had to maintain remotely. But we haven't bothered to install RemoteCmd at my new job and I'm getting tired of not having it so I'll probably be playing around with it soon enough. (:
-
tye
(but my friends call me "Tye")
| [reply] |
I'm not sure if this will work, but you may want to look into gaggio's code - Getting a Local/Remote Win32 Task List. You can grab a list of processes from a remote machine - and use it with a combination of Win32::Process, in order to actually kill the unwanted process. | [reply] |
It seems that this person wants a method to terminate a task
that was not created by Win32::Process::Create. Win32::Process
does not seem to allow control of such processes (at least
not in the exported methods). I have done some research
today looking for a module that might allow it, but other
than resorting to a Win32API system call, I cannot find one.
Update: I have refreshed my memory on Win32
system calls, and it does not appear to be possible to use
an API call to kill a window unless the killer spawned the
process. It is quite possible that there is something that
I don't know about that will do this, as I am by no means
a Win32 guru, but it looks to me like it is not ... or it's
very difficult.
| [reply] |
As mentionned by LD2, I uploaded some code a while ago about getting a remote task list. This code works - I testet it again this morning. If you want to try it out, since it is in the form of a function, just add the function get_remote_process_list() in a main program that looks like this:
use Win32::PerfLib;
%tasklist = get_remote_process_list($_[0]);
foreach $pid (keys %tasklist)
{
print "$pid -- $tasklist{$pid}\n";
}
Now, good remarks have been posted in this thread so far. I guess the most important thing for you, RayRay459, is to know that it is impossible to kill a task remotely if you haven't created it yourself. This is why I wrote along with my code submission that one needs a little more work and create a client-server interface. The way I did it here at my company is that a hidden server runs on each remote-controlled machine, and the client talks to it through some kind of protocol. Creating and killing tasks is always done by the server. The server keeps a list of running tasks that it created, and is able to kill all of those. It is definitely possible to not keep the tasks in a list and look for a particular task by its name, but this could be a little dangerous...
Finally, the whole stuff on the client side can be a CGI to have some kind of "UI" in a web browser! It looks pretty cool here!
Good luck RayRay459, and sorry to not have replied to your email - I lost your address.
Father gaggio . | [reply] [d/l] [select] |
Thanks again for your help michel. I really appreciate you taking time to answer me back. I will try to hack on the CGI UI stuff and see what i can come up with.
Thanks,
Ray
| [reply] |