Zerotoinfinity
Zerotoinfinity

Reputation: 6540

Remote computer drive information is not precise

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

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.

Upvotes: 1

Views: 966

Answers (1)

Gusman
Gusman

Reputation: 15171

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

Upvotes: 3

Related Questions