查询远程服务器上磁盘空间的最佳方法
我试图通过查询所有驱动器然后循环直到找到我正在寻找的驱动器来确定远程服务器上的可用空间。
有一个更好的方法吗?
Dim oConn As New ConnectionOptions
Dim sNameSpace As String = "\\mnb-content2\root\cimv2"
Dim oMS As New ManagementScope(sNameSpace, oConn)
Dim oQuery As System.Management.ObjectQuery = New System.Management.ObjectQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3")
Dim oSearcher As ManagementObjectSearcher = New ManagementObjectSearcher(oMS, oQuery)
Dim oReturnCollection As ManagementObjectCollection = oSearcher.Get()
Dim oReturn As ManagementObject
For Each oReturn In oReturnCollection
'Disk name
Console.WriteLine("Name : " + oReturn("Name").ToString())
'Free Space in bytes
Dim sFreespace As String = oReturn("FreeSpace").ToString()
If Left(oReturn("Name").ToString(), 1) = "Y" Then
Console.WriteLine(sFreespace)
End If
Next
I am trying to nail down free space on a remote server by querying all the drives and then looping until I find the drive I am seeking.
Is there a better way to do this?
Dim oConn As New ConnectionOptions
Dim sNameSpace As String = "\\mnb-content2\root\cimv2"
Dim oMS As New ManagementScope(sNameSpace, oConn)
Dim oQuery As System.Management.ObjectQuery = New System.Management.ObjectQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3")
Dim oSearcher As ManagementObjectSearcher = New ManagementObjectSearcher(oMS, oQuery)
Dim oReturnCollection As ManagementObjectCollection = oSearcher.Get()
Dim oReturn As ManagementObject
For Each oReturn In oReturnCollection
'Disk name
Console.WriteLine("Name : " + oReturn("Name").ToString())
'Free Space in bytes
Dim sFreespace As String = oReturn("FreeSpace").ToString()
If Left(oReturn("Name").ToString(), 1) = "Y" Then
Console.WriteLine(sFreespace)
End If
Next
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不让你的 WMI 查询只在 name='Y' 的地方拉回呢?
所以:
Why not just make your WMI query only pull back where name='Y'?
So: