Using IIS6 to run kill process. Executable hangs

Posted by David on Server Fault See other posts from Server Fault or by David
Published on 2012-06-04T19:17:57Z Indexed on 2012/06/05 16:41 UTC
Read the original article Hit count: 249

Filed under:
|
|

I'm using the following code (any tried many variations) in a web page that is supposed to kill a process on the server:

    Process scriptProc = new Process();
    SecureString password = new SecureString();
    password.AppendChar('p');
    password.AppendChar('s');
    password.AppendChar('s');
    password.AppendChar('w');
    password.AppendChar('d');
    scriptProc.StartInfo.UserName = "mylocaluser";
    scriptProc.StartInfo.Password = password;
    scriptProc.StartInfo.FileName = @"C:\WINDOWS\System32\WScript.exe";
    scriptProc.StartInfo.Arguments = @"c:\windows\system32\killMyApp.vbs";
    scriptProc.StartInfo.UseShellExecute = false;
    scriptProc.Start();
    scriptProc.WaitForExit();
    scriptProc.Close();

The VBS file is supposed to kill a w3wp.exe process, but never works. There are no errors in the application log. It works locally.

I noticed WScript.exe is in task manager every time I run the page, and never goes away.

The process WScript.exe (and I tried others such a psexec.exe) is being run as a local user with admin rights (and I tried other types of users including domain admins) when run from IIS, but it works when run from the command line on the server.

© Server Fault or respective owner

Related posts about iis6

Related posts about c#