开发者

How to run IISWeb.vbs command in an asp.net application

Can somebody please help me in executing the IISWeb.vbs commands from the c# code which I am trying to use for starting and stopping the websites on remote IIS servers (IIS 6.0).

I have tried other options like using DirectorServises with SyytemManagement or with WMI but in all cases code works fine for the local IIS server but displays error for the remote servers. I get 'Access denied' error for remote servers

I have got the all the servers in the same domian and network area and trying with a user account with administrative priviledge but nothing works for remote machine so giving it a try using IISWeb.vbs.

Please note that from my dev machine I am able to stop and start the websites on remote machines using this IISWeb.vbs commands without any problem when I run it from command prompt. So definitely there is no permission issues. Code I am using:

        Process p = new Process();
        p.StartInfo.FileName = "cscript.exe";
        p.StartInfo.Arguments = "iisweb.vbs /stop w3svc/87257621 test /s servername /u userid /p password";
        p.StartInfo.UseShellExecute = false;
        p.Start();
        p.WaitForExit();
        int i= p.ExitCode;

Surprisingly I am not getting any e开发者_Go百科rror and i get return code '0' but nothing but website is not getting stopped.

Please help me out.


Figured out the problem, code was trying to find out the iisweb.vbs file inside c:\program files\Visual Studio\.........and was unable to find it out. So I amended the code to specifically look for the iisweb.vbs file at C:\Windows\System32 location and it is working fine now.

Here is the working version of code for stopping and starting a website on remote machine having IIS 6.0.

       ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
       psi.FileName = @"C:\WINDOWS\system32\cscript.exe";
       psi.Arguments = @"C:\WINDOWS\system32\iisweb.vbs /stop w3svc/1 test /s ServerName /u UserId /p Password";
       psi.RedirectStandardOutput = true;
       psi.WindowStyle = ProcessWindowStyle.Hidden;
       psi.UseShellExecute = false; 
       System.Diagnostics.Process listFiles; 
       listFiles = System.Diagnostics.Process.Start(psi);
       System.IO.StreamReader myOutput = listFiles.StandardOutput; 
       listFiles.WaitForExit(2000); 
       if (listFiles.HasExited) 
       {
           string output = myOutput.ReadToEnd();
           //this.processResults.Text = output;
       }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜