以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]大佬协助改下C#转过来的代码  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=157064)

--  作者:jiskin
--  发布时间:2020/9/30 9:19:00
--  [求助]大佬协助改下C#转过来的代码
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#转换过来的 但是执行有点问题,帮忙看看,谢谢

--  作者:有点蓝
--  发布时间:2020/9/30 9:36:00
--  
网上找的代码吧,NetManager.GetRemoteHostName是一个自定义的函数,人家没有给出来,应该是根据ip获取对应的机器名的,参考:https://www.baidu.com/baidu?word=c%23+根据ip获取机器名