关于vb.net:查询远程服务器磁盘空间的最佳方式

关于vb.net:查询远程服务器磁盘空间的最佳方式

Best way to query disk space on remote server

我试图通过查询所有驱动器然后循环直到找到我正在寻找的驱动器来确定远程服务器上的可用空间。
有一个更好的方法吗?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Dim oConn As New ConnectionOptions
Dim sNameSpace As String ="\\\\mnb-content2\
oot\\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

为什么不让你的 WMI 查询只在 name=\\'Y\\' 的地方拉回?

所以:

1
Dim oQuery As System.Management.ObjectQuery = New System.Management.ObjectQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3 AND name='Y'")


推荐阅读