Script读写注册表获取网络配置


注意修改这里 2改为1,依赖于你自己的机器配置
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\2\ServiceName
————————————————————————


Option Explicit
Dim WSHShell
Dim sNic, sMan
Dim Gateway
Dim IPAddress
Dim SubnetMask
Dim i

Dim sTcpipRegKey
Dim bIsDHCP

Set WSHShell = CreateObject("WScript.Shell")
sNic = WSHShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\2\ServiceName")

If sTcpipRegKey <> "Microsoft" And Err.Number = 0 Then

  sTcpipRegKey = "HKLM\SYSTEM\CurrentControlSet\Services\" & sNic & "\Parameters\Tcpip\"

  bIsDHCP = WSHShell.RegRead(sTcpipRegKey & "EnableDHCP")
  If bIsDHCP Then
    Gateway = WSHShell.RegRead(sTcpipRegKey & "DhcpDefaultGateway")
    IPAddress = WSHShell.RegRead(sTcpipRegKey & "DhcpIPAddress")
    SubnetMask = WSHShell.RegRead(sTcpipRegKey & "DhcpSubnetMask")
    MsgBox ("DefaultGateway: " & Gateway(0) & Chr(10) & Chr(13) & "IPAddress: " & IPAddress & Chr(10) & Chr(13) & "SubnetMask: " & SubnetMask)
  Else
    Gateway = WSHShell.RegRead(sTcpipRegKey & "DefaultGateway")
    IPAddress = WSHShell.RegRead(sTcpipRegKey & "IPAddress")
    SubnetMask = WSHShell.RegRead(sTcpipRegKey & "SubnetMask")
    For i=0 to Ubound(IPAddress)-1
        MsgBox ("DefaultGateway: " & Gateway(0) & Chr(10) & Chr(13) & "IPAddress: " & IPAddress(i) & Chr(10) & Chr(13) & "SubnetMask: " & SubnetMask(i))
    Next
  End If
End If

作者:anonymous   更新日期:2004-12-23
来源:internet   浏览次数:

相关文章

相关评论   发表评论