2011-03-22 69 views
0

有人可以幫我在執行Iisweb.vbs將從中我想使用啓動和停止在遠程的IIS服務器的網站上的C#代碼指令(IIS 6.0)。如何在asp.net應用程序運行Iisweb.vbs將命令

我已經嘗試了其他選項,如使用帶有SyytemManagement或WMI,但在所有情況下的代碼工作正常本地IIS服務器,但遠程服務器顯示錯誤DirectorServises。我得到遠程服務器的「訪問被拒絕」錯誤

我已經得到了所有的服務器在同一個多米安和網絡區域,並嘗試用管理權限的用戶帳戶,但沒有用於遠程機器,所以試試使用IISWeb .VBS。

請注意,從我的開發機器我可以停下來,用這個Iisweb.vbs將沒有任何問題的命令,當我從命令提示符下運行啓動遠程計算機上的網站。所以肯定沒有許可問題。 代碼我使用:

 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; 

令人驚訝的,我沒有得到任何錯誤,我得到的返回碼「0」,但無非是網站沒有得到停止。

請幫我一把。

回答

0

想通了這個問題,代碼試圖找出裏面c:\program files\Visual Studio\的Iisweb.vbs將文件.........,無法找到它了。因此,我修改了代碼,專門查找位於C:\Windows\System32位置的iisweb.vbs文件,現在它工作正常。

這裏的代碼在具有遠程計算機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; 
     } 
相關問題