转换为 Int64 或任何大数字时,我在以下代码上遇到问题。任何帮助表示赞赏。
public static void GetDiskspace(string MachineName, string DriveLetter)
{
ConnectionOptions options = new ConnectionOptions();
ManagementScope scope = new ManagementScope("\\\\" + MachineName + "\\root\\cimv2",
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
if (mo["Name"].Equals(DriveLetter.ToUpper()+":"))
if (((Int64)mo["FreeSpace"]) < (1024 * 1024 * 100)) //100GB <<----HERE IS WHERE I GET THE ERROR
{
Console.WriteLine(MachineName + " ALERT. LOW SPACE ON DRIVE " + mo["Name"]);
Console.WriteLine();
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();
}
编辑:将“大小”更改为“自由空间”。