Trying to run psexec to remote to server and recycle app pool

Posted by James on Stack Overflow See other posts from Stack Overflow or by James
Published on 2010-12-21T22:40:55Z Indexed on 2010/12/21 22:54 UTC
Read the original article Hit count: 315

If I run this from my command prompt it works fine.

psexec \ServerName cscript.exe iisapp.vbs /a AppName /r

I'm trying to do the same thing with C# console app. I'm using the below code but most of the time the application hangs and doesn't complete, and the few times it does it throws an error code. Am I doing this wrong? Anyone know where I can look up the error or error code?

static void RecycleAppPool(string sServer)
        {
            Console.Clear();
            ProcessStartInfo p = new ProcessStartInfo("psexec.exe", "\\\\" + sServer + " cscript.exe iisapp.vbs /a <AppName> /r");
            p.RedirectStandardInput = true;
            p.UseShellExecute = false;
            Process.Start(p);
        }

When it completes with error, looks like this

"cscript.exe exited with error code -2147024664"

© Stack Overflow or respective owner

Related posts about c#

Related posts about remote