我有一个运行 Server 2008 R2 的 Web 服务器工作组,我试图在其中管理一个检查所有服务器磁盘空间的脚本。几个月前我在设置服务器时设置了这个,我相信它工作正常。现在我去检查,它给出了一个错误,说“RPC 服务器不可用”。该脚本是一个 C# ASP.NET 页面,尽管我在 PowerShell 中尝试过类似的调用,但它给出了相同的错误。该脚本可以正常访问本地计算机的信息,但无法访问远程服务器信息。
在过去的几个小时里,我一直在挖掘我能找到的所有东西,但没有任何效果。我已经为 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);
}
“/”应用程序中的服务器错误。
RPC 服务器不可用。(来自 HRESULT 的异常:0x800706BA)
说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.Runtime.InteropServices.COMException:RPC 服务器不可用。(来自 HRESULT 的异常:0x800706BA)
源错误:
Line 64: Line 65: //获取结果 Line 66: ManagementObjectCollection oReturnCollection = oSearcher.Get(); 第 67 行:第 68 行://遍历找到的驱动器并写出信息
源文件:c:\Web\medelaimages.com\iis\tool\boxinfoagent.aspx 行:66
堆栈跟踪:
[COMException (0x800706ba): RPC 服务器不可用。(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
版本信息:Microsoft .NET Framework 版本:4.0.30319;ASP.NET 版本:4.0.30319.1