2010获取远程PC硬盘大小

2010获取远程PC硬盘大小

本文介绍了使用vb.net 2010获取远程PC硬盘大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人有想法吗?我的代码显示的是逻辑磁盘,而不是C:的物理磁盘.

Does anyone have an idea? My code displays the logical disk and not the physical disk of C: .

Private Function GetDiskSize()
        Dim diskSize As Double
        'Dim oConn As ConnectionOptions = New ConnectionOptions()
        'Dim passWord As string
        'oConn.Username = InputBox("User Name Please", "Credentials: Username...")
        'oConn.Password = InputBox("Password Please", "Credentials: Password...")
        Dim oMs As New Management.ManagementScope("\\" & computerName & "\root\cimv2")
        'Dim oMs As System.Management.ManagementScope = New System.Management.ManagementScope("\\" & computerName & "\root\cimv2", oConn)
        Dim query As ObjectQuery
        query = New ObjectQuery("SELECT  Size,   FROM Win32_LogicalDisk where DriveType=3")
        Dim searcher As ManagementObjectSearcher
        searcher = New ManagementObjectSearcher(oMs, query)
        Dim queryCollection As ManagementObjectCollection
        queryCollection = searcher.Get()
        Dim m As ManagementObject
        For Each m In queryCollection
            ' Display the remote computer information
            diskSize = Format(m("size") / 1024 ^ 3, "0.00")
            'diskSize= diskSize.ToString() & " Gb"
            '"Size :" + m("size").ToString
            ''+ vbCrLf + Label1.Text
            'Label2.Text = "FreeSpace :" + m("freespace").ToString
            ''+ vbCrLf + Label2.Text
            'lblRequiredDiskSize.text = "Name : " + m("name")
            '+ vbCrLf + Label3.Text
        Next
        Return diskSize
    End Function

推荐答案


这篇关于使用vb.net 2010获取远程PC硬盘大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 08:35