查询远程服务器上磁盘空间的最佳方法

发布于 2024-07-04 17:00:05 字数 886 浏览 4 评论 0原文

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终难愈 2024-07-11 17:00:05

为什么不让你的 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'")

Why not just make your WMI query only pull back where name='Y'?

So:

Dim oQuery As System.Management.ObjectQuery = New System.Management.ObjectQuery("select FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3 AND name='Y'")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文