Public Function GetQueryObject(ByVal ip As String, ByVal username As String, ByVal password As String, ByVal queryString As String) As System.Management.ManagementObjectCollection
Dim co As New System.Management.ConnectionOptions()
Dim hostname As String = If(Not String.IsNullOrEmpty(ip), NetManager.GetRemoteHostName(ip), "")
co.Username = (If(String.IsNullOrEmpty(hostname), "", hostname & "\" ) + username;"))
co.Password = password
Dim scm As ManagementScope = If(String.IsNullOrEmpty(ip) OrElse ip.Trim() = "" OrElse ip.ToLower().Trim() = "localhost" OrElse ip.ToLower().Trim() = "127.0.0.1", New ManagementScope("\localhost\root\cimv2"), New ManagementScope("\" & ip & "\root\cimv2", co))
Dim oq As ObjectQuery = New System.Management.ObjectQuery(queryString)
Dim query As ManagementObjectSearcher = New ManagementObjectSearcher(scm, oq)
Return query.[Get]()
End Function
这是C#转换过来的 但是执行有点问题,帮忙看看,谢谢