vb轻松获取计算机名,用户名 域名
以前都用api做,后来发现,不用api也很轻松搞定 Dim a As Object
Set a = CreateObject("Wscript.Network")
Print a.ComputerName
Print a.UserName
Print a.UserDomain
Private Sub Command1_Click()
'IP 是ip地址
'Phy 是 mac地址
'Host 是 主机名
'DNS 是 dns
'Def 是缺省网关
'Sub 是 子网掩码
MsgBox strGetIpAdress("Sub")
End Sub
Private Function strGetIpAdress(InIp) As String
Dim wsShell, re, myIp, r, strLine
Set wsShell = CreateObject("WScript.Shell")
Set re = CreateObject("vbScript.RegExp")
re.Pattern = InIp
Set myIp = wsShell.Exec("ipconfig /all")
While Not myIp.StdOut.AtEndOfStream
strLine = myIp.StdOut.ReadLine()
r = re.Test(strLine)
If r Then
strGetIpAdress = Mid(strLine, InStrRev(strLine, ":") + 1)
End If
Wend
End Function
传参数注意大小写就可以了!