rrwo has asked for the wisdom of the Perl Monks concerning the following question:

I've tried the examples in Roth's SysAdmin for Win32 book, and cannot kill off processes like inetinfo.exe ... does anybody have sample code that can do this? I'd like to write a server (using Win32::Daemon) that will test if a web site responds and if not kill the web server and restart it.

Replies are listed 'Best First'.
Re: Killing processes in Win32...?
by John M. Dlugosz (Monsignor) on Jun 20, 2001 at 23:58 UTC
    It's probably a security thing. A script run on the command line can't kill a "system" program. However, you can run the script under a system account, itself. Having one service kill the other is probably going to work if they both are configured the same way.

    Do you have to kill the web server, or can you "net stop" it? That worked for me when PerlScript started hanging. I implemented a trivial loop that would test every few minutes and restart the sever if it seemed to be stuck.

    —John

      Actually, there is no privlege that allows killing of services (nor other system processes). You have to "stop" services. But if they won't go away when asked to stop, then you can force the process to exit by using the process debugging API to attach a thread to the process and then tell the thread to execute invalid code. I think the code for this can be found in the MS knowledge base.

              - tye (but my friends call me "Tye")

      If the user has System or Admin privs, it shouldn't be a security issue. The command-line <kbd>kill</kbd> utility that comes with the Resource Kit can kill the services (you have to kill <kbd>inetinfo.exe</kbd> and <kbd>mtx.exe</kbd>).

      Naturally one does not want to try running shell commands from a service (I was thinking of using Win32::Daemon).

      Sometimes something crashes the inetnet service, so it does not respond to <kbd>net stop</kbd>... otherwise I'd not need to ask the question.

        Did you ever get anywhere with this? I am trying to do the same thing. I want to connect to a remote server and kill inetinfo.exe if net stop w3svc fails and also restart it without using something like WRSHDNT. If you have any info, i would greatly appreciate it. Thnx ~Ray~