其實就是讀注冊表,不過如果能獲得機器的ip配置等信息,以後配置IIS時就簡單了。下面的腳本讀出機器的所有可用IP地
址,子網掩碼,卻省網關等信息:
代碼:
--------------------------------------------------------------------------------
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\1\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
--------------------------------------------------------------------------------
說明:機器的網絡配置保存在注冊表裡,網卡項目下面,所以首先必須知道網卡的名字。然後取注冊表數據,IP地址和子網掩
碼都是數組形式(其實注冊表裡保存的是二進制數據,VBSCRIPT幫我們轉換了)。在WSH裡讀注冊表非常的簡單,具體請看上面的
程序。