我有一個運行Server 2008 R2的Web服務器工作組,我試圖管理一個檢查所有這些磁盤空間的腳本。幾個月前,我在設置服務器時設置了這一點,我相信它工作正常。現在我去檢查,它給出了一個錯誤,說「RPC服務器不可用」。該腳本是一個C#ASP.NET頁面,雖然我嘗試過在PowerShell中進行類似的調用,但它給出了相同的錯誤。該腳本正常工作以訪問本地計算機的信息,但無法訪問遠程服務器信息。「RPC服務器不可用」使用WMI查詢
我已經花了最後幾個小時挖掘我能找到的所有東西,但沒有任何工作。我爲WMI(遠程&本地),DCOM(遠程&本地)以及我正在訪問的計算機的整個驅動器設置了權限。我使用了計算機名稱,IP地址,完整的計算機名稱(xxx.echomountain.com),並在ConnectionOptions對象上嘗試了大量的模擬和身份驗證設置。
我知道用戶名/密碼,我使用的是正確的,因爲我可以從別的什麼其他
任何想法訪問一個的碎片目錄,我可以檢查可能導致這個錯誤?
ConnectionOptions oConn = new ConnectionOptions();
oConn.Impersonation = ImpersonationLevel.Impersonate;
oConn.EnablePrivileges = true;
oConn.Username = username;
oConn.Password = password;
//oConn.Authentication = AuthenticationLevel.PacketPrivacy;
string strNameSpace = @"\\";
if (srvname != "")
strNameSpace += srvname + ".echomountain.com";
else
strNameSpace += ".";
strNameSpace += @"\root\cimv2";
ManagementScope oMs = new ManagementScope(strNameSpace, oConn);
//get Fixed disk state
ObjectQuery oQuery = new ObjectQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3");
//Execute the query
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);
//Get the results
ManagementObjectCollection oReturnCollection = oSearcher.Get();
//loop through found drives and write out info
double D_Freespace = 0;
double D_Totalspace = 0;
foreach (ManagementObject oReturn in oReturnCollection)
{
// Disk name
//MessageBox.Show("Name : " + oReturn["Name"].ToString());
// Free Space in bytes
string strFreespace = oReturn["FreeSpace"].ToString();
D_Freespace = D_Freespace + System.Convert.ToDouble(strFreespace);
// Size in bytes
string strTotalspace = oReturn["Size"].ToString();
D_Totalspace = D_Totalspace + System.Convert.ToDouble(strTotalspace);
boxSize = (D_Totalspace/GB).ToString("##.00");
boxFree = (D_Freespace/GB).ToString("##.00");
Response.Write(srvname + ":" + boxSize + ":" + boxFree);
}
Server Error in '/' Application.
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
Source Error:
Line 64: Line 65: //Get the results Line 66: ManagementObjectCollection oReturnCollection = oSearcher.Get(); Line 67: Line 68: //loop through found drives and write out info
Source File: c:\Web\medelaimages.com\iis\tool\boxinfoagent.aspx Line: 66
Stack Trace:
[COMException (0x800706ba): The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)] System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) +0 System.Management.ManagementScope.InitializeGuts(Object o) +674 System.Management.ManagementScope.Initialize() +347 System.Management.ManagementObjectSearcher.Initialize() +189 System.Management.ManagementObjectSearcher.Get() +54 ASP.tool_boxinfoagent_aspx.Page_Load(Object sender, EventArgs e) in c:\Web\medelaimages.com\iis\tool\boxinfoagent.aspx:66 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25 System.Web.UI.Control.LoadRecursive() +71 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3048
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
我得到相同的錯誤,但它是非常隨機的,我的意思是有時我得到這個錯誤,有時我沒有。它看起來取決於我使用的登錄類型。你如何登錄?域帳戶? – raz3r 2012-03-23 16:00:25
我的登錄在每臺服務器上單獨設置,但它們共享相同的憑據。我真的放棄瞭解決這個問題。如果你有工作,即使是間歇性的,我也會對你如何做這件事感興趣。 – jwynveen 2012-03-23 19:43:41
假設您的腳本在域計算機上運行,您應該沒有任何問題,而如果您在域外運行,請嘗試使用DOMAIN \\用戶名作爲用戶名。如果我使用DOMAIN \\用戶名作爲登錄,我不會收到錯誤(大部分時間)。 – raz3r 2012-03-24 09:57:22