远程计算机驱动器信息不准确 [英] Remote computer drive information is not precise

查看:38
本文介绍了远程计算机驱动器信息不准确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要获取我使用的远程计算机的可用磁盘空间,请使用以下代码

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

  • 它给了我 B:/, C:/, D;/, E:/和 Z:/,但在服务器上我实际上有 C:/, D:/, E:/, F:/, G:/, H:/, I:/, L:/和 z:/为什么我没有获得所有驱动器状态?
  • 驱动器空间信息也不准确;例如:对于 D 驱动器,我通过这段代码得到429496725504 字节",它是 400 GB,但实际上在我的服务器上 D:/是 415 GB

我哪里出错了?

编辑 - 可能的原因

我刚刚检查并发现运行此代码的服务器有 B:/、C:/、D;/、E:/和 Z:/以及 D:/有 400 GB.这意味着,无论我提供什么 IP 地址,它都会获取我运行代码的计算机的详细信息.

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.

推荐答案

管理范围缺少一些路径部分,正确的应该是:

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

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

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

这篇关于远程计算机驱动器信息不准确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆