5

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

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
4

1 回答 1

9

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

所以:

Dim oQuery As System.Management.ObjectQuery = New System.Management.ObjectQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3 AND name='Y'")
于 2008-09-11T14:45:31.853 回答