使用vb.net 2010获取远程PC硬盘大小 [英] Get remote pc hard disk size using vb.net 2010

查看:80
本文介绍了使用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

推荐答案

本文:
如何获取硬件信息(CPU ID,主板信息,硬盘序列号,系统信息等) [ ^ ]

显示您可以从您在代码中使用的ManagementObjectSearcher对象获得的所有不同信息.您可以尝试Win32_PhysicalMemory一个...但是我不确定它是否正是您想要的.
This article:
How To Get Hardware Information (CPU ID, MainBoard Info, Hard Disk Serial, System Information , ...)[^]

shows all of the different bits of info you can get from the ManagementObjectSearcher object that you are sort of using in your code. You could try the Win32_PhysicalMemory one...but I''m not sure if it''s exactly what you are looking for.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆