如何使用代码获取远程计算机的 windows 版本

how to get windows version for remote computer using code

我正在使用 visual studio 2013 开发小型应用程序,VB 以扫描同一网络中的 IP 地址范围

我的应用程序将使用 IP 和 return

Ping 状态(真或假)

计算机名称

MAC地址

一切正常

我的问题是我是否需要远程计算机 windows(xp 或 7 或 8)

使用 IP 地址或计算机名称我该怎么做?

Dim osVer As String
osVer = System.Environment.OSVersion.ToString
   Using wClient As New WebClient
                   dim myip as string = wClient.DownloadString("http://tools.feron.it/php/ip.php")

                End Using

可能有助于轻松找到 ip。祝你好运

最后我使用系统管理如下

(导入后 System.Management)

我用了两个函数

第一个连接远程计算机然后收集数据

Private Function tryConnect(SystemName As String)
        Try
            Dim ComputerConnection As New System.Management.ConnectionOptions
            ' to add user name and password
            'ComputerConnection.Username = "UserName"
            'ComputerConnection.Password = "Password"

            With ComputerConnection
                .Impersonation = System.Management.ImpersonationLevel.Impersonate
                .Authentication = System.Management.AuthenticationLevel.Packet

            End With
            'connect to WMI
            MyMgtScope = New System.Management.ManagementScope("\" & SystemName & "\root\CIMV2", ComputerConnection)
            MyMgtScope.Connect()
            Return MyMgtScope.IsConnected
        Catch ex As Exception
            Return False
        End Try
End Function

private sub GetOsdata()
    if tryConnect(remoteComputerName) = False then Exit Sub ' or show some message
    Dim MyMgtScope As System.Management.ManagementScope
    Dim MyObjSearcher As System.Management.ManagementObjectSearcher
    Dim MyColl As System.Management.ManagementObjectCollection
    Dim MyObj As System.Management.ManagementObject
    Dim ComputerOSVersion , ComputerOSServiceBack ,OSbit As String
    MyObjSearcher = New System.Management.ManagementObjectSearcher(MyMgtScope.Path.ToString, "Select * FROM Win32_OperatingSystem")
                ' Execute the query
    MyColl = MyObjSearcher.Get
                For Each MyObj In MyColl
                    ComputerOSVersion = MyObj.GetPropertyValue("Caption").ToString
                    ComputerOSServiceBack = MyObj.GetPropertyValue("ServicePackMajorVersion").ToString
                    OSbit = MyObj.GetPropertyValue("OSArchitecture").ToString
               Next

               MyObjSearcher = Nothing
               MyColl = Nothing
End Sub