我如何从远程计算机的驱动器获得可用自由空间? [英] How do I get the available FreeSpace from a drive from a remote computer?

查看:183
本文介绍了我如何从远程计算机的驱动器获得可用自由空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从远程计算机的D盘的自由空间。



接近年底,我得到一个ManagementException是由用户代码未处理未找到



这是给我的错误行:FS = M [自由空间]的ToString();



下面是我的代码:

  ConnectionOptions oConn =新ConnectionOptions(); 

oConn.Username =用户名;
oConn.Password =密码;
oConn.Authority =ntlmdomain:XXX;

管理范围范围=新的管理范围(\\\\Remote_Computer\\root\\CIMV2,oConn);

scope.Connect();

的ObjectQuery查询=新的ObjectQuery(选择的DeviceID,卷名FROM的Win32_LogicalDisk那里的DeviceID ='D:');

ManagementObjectSearcher搜索=新ManagementObjectSearcher(范围,查询);

ManagementObjectCollection queryCollection = searcher.Get();

的foreach(在queryCollection的ManagementObject米)
{这里
//错误发生
FS = M [自由空间]的ToString()。

FREESPACE = Convert.ToInt64(FS);
}


解决方案

我发现了什么问题了。



我的查询是错误的。我取代了它:

 选择自由空间FROM的Win32_LogicalDisk那里的DeviceID ='D:'

和问题解决了。


I'm trying to get the FreeSpace from the D drive of a remote computer.

Towards the end, I'm getting a ManagementException was unhandled by user code "Not Found"

This is the line that gives me the error: fs = m["FreeSpace"].ToString();

Here's my code:

ConnectionOptions oConn = new ConnectionOptions();

oConn.Username = "username";
oConn.Password = "password";
oConn.Authority = "ntlmdomain:XXX";

ManagementScope scope = new ManagementScope("\\\\Remote_Computer\\root\\CIMV2", oConn);

scope.Connect();

ObjectQuery query = new ObjectQuery("SELECT DeviceID, VolumeName FROM Win32_LogicalDisk where DeviceID = 'D:'");

ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);

ManagementObjectCollection queryCollection = searcher.Get();

foreach (ManagementObject m in queryCollection)
{
      //error happens here
      fs = m["FreeSpace"].ToString();

      freeSpace = Convert.ToInt64(fs);
}

解决方案

I found out what the issue was.

My query was wrong. I replaced it with:

"SELECT FreeSpace FROM Win32_LogicalDisk where DeviceID = 'D:'"

And problem solved.

这篇关于我如何从远程计算机的驱动器获得可用自由空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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