要获取我在代码
下面使用的远程计算机的可用磁盘空间ConnectionOptions options = new ConnectionOptions();
ManagementScope scope = new ManagementScope("\\\\SYSTEM_IP",
options);
scope.Connect();
SelectQuery query1 = new SelectQuery("Select * from Win32_LogicalDisk");
ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(scope, query1);
ManagementObjectCollection queryCollection1 = searcher1.Get();
foreach (ManagementObject mo in queryCollection1)
{
// Display Logical Disks information
Console.WriteLine(" Disk Name : {0}", mo["Name"]);
Console.WriteLine(" Disk Size : {0}", mo["Size"]);
Console.WriteLine(" FreeSpace : {0}", mo["FreeSpace"]);
Console.WriteLine(" Disk DeviceID : {0}", mo["DeviceID"]);
Console.WriteLine(" Disk VolumeName : {0}", mo["VolumeName"]);
Console.WriteLine(" Disk SystemName : {0}", mo["SystemName"]);
Console.WriteLine("Disk VolumeSerialNumber : {0}", mo["VolumeSerialNumber"]);
Console.WriteLine();
}
string line;
line = Console.ReadLine();
}
这给了我与服务器驱动器不完全匹配的结果
我哪里错了?
编辑 - 可能的原因
我刚检查并发现我运行此代码的服务器有B:/,C:/,D; /,E:/和Z:/和D:/有400 GB。所以这意味着,无论我提供什么IP地址,它都会记录我运行代码的计算机的详细信息。
答案 0 :(得分:3)
管理范围缺少一些路径部分,正确的部分应该是:
ManagementScope scope = new ManagementScope("\\\\FullComputerName\\root\\cimv2");
来源:http://msdn.microsoft.com/en-us/library/ms257337%28v=vs.80%29.aspx