我试图从远程计算机的d驱动器的自由空间。
接近年底,我得到一个ManagementException是由用户代码未处理的“找不到”
这是给我的错误的行:FS = M [“自由空间”]的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);
}