Public Function GetIP
Set WS = CreateObject("WScript.Shell")
Set aExec = WS.exec("ipconfig")
Set aStdOut = aExec.StdOut
ipconfig = aStdOut.Readall
If InstrRev(ipconfig,"宽带连接",-1,1)=0 then
GetIP=-1
Else
GetIP=InstrRev(ipconfig,":",-1,1)
GetIP=Right(ipconfig,len(ipconfig)-GetIP)
GetIP=trim(GetIP)
GetIP=replace(GetIP,chr(10),"")
GetIP=replace(GetIP,chr(13),"")
End If
set WS = nothing
End Function
这个是我自己写的判断IP的调用(没连接返回-1),就是从ipconfig里找Ip,但是.exec没法完全隐藏dos窗口,我不想写txt再删除,不知道有其他好的办法没
这个是网上找的,但是不知道为什么虚拟机里用不了
Public Function GetIP
ComputerName="."
Dim objWMIService,colItems,objItem,objAddress
GetIP_i=0
Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
GetIP_i=GetIP_i+1
For Each objAddress in objItem.IPAddress
If objAddress <> "" then
GetIP = objAddress
End If
Next
Next
If GetIP_i=1 then
GetIP=-1
End If
End Function
没连接返回-1是我自己加上去的,我看不大懂,虚拟机里卡在Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2")这句上了,不知道为什么
有了调用,其他就简单了,就不发了,大家帮我看看哈:D
[ Last edited by sexfio on 2009-4-15 at 22:19 ]