Remote computer drive information is not precise

感情迁移 提交于 2019-12-24 14:13:40

问题


To get the free disk space of the remote computer I am using below code

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();

    }

This is giving me result which is not exactly matching with server drive

  • It is giving me B:/ , C:/, D;/, E:/ and Z:/, but on server I actually have C:/, D:/, E:/, F:/, G:/, H:/, I:/, L:/ and z:/ Why I am not getting all drive status?
  • The drive space information is also not precise; ex.: for D drive I am getting "429496725504 bytes" by this code which is 400 GB but actually on my server D:/ is 415 GB

Where I am going wrong?

EDIT - Possible reason

I just checked and found out that the server on which I am running this code have B:/ , C:/, D;/, E:/ and Z:/ and D:/ have 400 GB. So that means, no matter what IP address I am providing it is taking details of the computer on which I am running my code.


回答1:


The management scope is missing some path parts, the correct one should be:

ManagementScope scope = new ManagementScope("\\\\FullComputerName\\root\\cimv2");

Source: http://msdn.microsoft.com/en-us/library/ms257337%28v=vs.80%29.aspx



来源:https://stackoverflow.com/questions/23291510/remote-computer-drive-information-is-not-precise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!