我正在尝试从远程计算机的 D 驱动器获取 FreeSpace。
最后,我收到用户代码“未找到”未处理的 ManagementException
这是给我错误的行: 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:'"
问题解决了。
关于c# - 如何从远程计算机的驱动器获取可用的可用空间?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12603641/