我正试图从远程计算机的D盘中获取FreeSpace.
接近尾声,我收到一个ManagementException未被用户代码“Not Found”处理
这是给出错误的行:fs = m [“FreeSpace”].ToString();
这是我的代码:
ConnectionOptions oConn = new ConnectionOptions();
oConn.Username = "username";
oConn.Password = "password";
oConn.Authority = "ntlmdomain:XXX";
ManagementScope scope = new ManagementScope("\\\\Remote_Computer\\root\\CIMV2", oConn);
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT DeviceID, VolumeName FROM Win32_LogicalDisk where DeviceID = 'D:'");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
//error happens here
fs = m["FreeSpace"].ToString();
freeSpace = Convert.ToInt64(fs);
}
最佳答案 我发现了问题所在.
我的查询错了.我把它替换为:
"SELECT FreeSpace FROM Win32_LogicalDisk where DeviceID = 'D:'"
问题解决了.