none
读取局域网内机台信息 RRS feed

答案

  • Hi

    下面代码可以读出局域网内磁盘的信息,你可以试试。

    Imports System.Management
    
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim conn As ConnectionOptions = New ConnectionOptions()
            conn.Username = TextBox2.Text
            conn.Password = TextBox3.Text
    
            Dim str As String = "\\" & TextBox1.Text & "\root\cimv2"
    
            Dim MS As ManagementScope = New ManagementScope(str, conn)
            Try
                MS.Connect()
                Dim query As ObjectQuery = New ObjectQuery("select * from Win32_Diskdrive")
                Dim Searcher As ManagementObjectSearcher = New ManagementObjectSearcher(MS, query)
                Dim ReturnCollection As ManagementObjectCollection = Searcher.Get()
                For Each wmi_HD As ManagementObject In ReturnCollection
                    TextBox4.Text = Convert.ToDouble(wmi_HD("Size")) / (1024 * 1024 * 1024)
                Next
            Catch ex As Exception
                MsgBox(Err.Description)
            End Try
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 金灶沐 2018年7月25日 23:50
    2018年7月24日 3:36

全部回复

  • Hi

    下面代码可以读出局域网内磁盘的信息,你可以试试。

    Imports System.Management
    
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim conn As ConnectionOptions = New ConnectionOptions()
            conn.Username = TextBox2.Text
            conn.Password = TextBox3.Text
    
            Dim str As String = "\\" & TextBox1.Text & "\root\cimv2"
    
            Dim MS As ManagementScope = New ManagementScope(str, conn)
            Try
                MS.Connect()
                Dim query As ObjectQuery = New ObjectQuery("select * from Win32_Diskdrive")
                Dim Searcher As ManagementObjectSearcher = New ManagementObjectSearcher(MS, query)
                Dim ReturnCollection As ManagementObjectCollection = Searcher.Get()
                For Each wmi_HD As ManagementObject In ReturnCollection
                    TextBox4.Text = Convert.ToDouble(wmi_HD("Size")) / (1024 * 1024 * 1024)
                Next
            Catch ex As Exception
                MsgBox(Err.Description)
            End Try
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 金灶沐 2018年7月25日 23:50
    2018年7月24日 3:36
  • 谢谢你提供的代码

    2018年7月25日 23:50