查看本机网络属性的VBS

来源:互联网 发布:centos yum pip 编辑:程序博客网 时间:2024/05/21 21:43

'关键代码来自网络
' ----- ExeScript Options Begin -----
' ScriptType: window
' DestDirectory: temp
' Icon: default
' OutputFile:

' ----- ExeScript Options End -----
option explicit
dim strComputer
dim strResult
dim objWMIService
dim IPConfigSet
dim IPConfig
dim strAddress
dim colComputers
dim objComputer
dim strMac
strComputer = "."
strResult = "IP: "
Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each IPConfig in IPConfigSet 
 If Not IsNull(IPConfig.IPAddress) Then 
  For Each strAddress in IPConfig.IPAddress 
   strResult = strResult & strAddress & " "  
  Next 
 End If 
Next
strResult = strResult & vbCrLf & "主机名为 "
strComputer = "." 
Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2") 
Set colComputers = objWMIService.ExecQuery("Select * from Win32_ComputerSystem") 
For Each objComputer in colComputers 
 strResult = strResult & objComputer.Name & vbCrLf
Next
set colComputers = objWMIService.ExecQuery("Select MACAddress from Win32_NetworkAdapterConfiguration")
strResult = strResult & vbCrlf & "MAC地址 " & vbCrlf
for each IPConfig in colComputers
 if not IsNull(IPConfig.MACAddress) then
  strResult = strResult & IPConfig.MACAddress & vbCrlf
 end if
next
Wscript.Echo strResult

原创粉丝点击