代码如下:
Set WshShell = CreateObject("WScript.Shell")Set oExec = WshShell.Exec("ipconfig.exe")Set oStdOut = oExec.StdOutip = ""Do Until oStdOut.AtEndOfStream strLine = oStdOut.ReadLine If InStr(strLine, "本地连接") > 0 Then strLine = oStdOut.ReadLine strLine = oStdOut.ReadLine strLine = oStdOut.ReadLine ip = Mid(strLine, InStr(strLine, ":") + 2) Exit Do End IfLoopIf ip = "" Then MsgBox "获取本地连接IP地址失败!", vbExclamation, "错误"Else MsgBox ip, vbExclamation, ipEnd If