在论坛上我看到两种写入IP的方式。
第一种是:
$colItems = ""
$objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
Dim $SetIPAddress[1]
$SetIPAddress[0] = IniRead($dir, $SectionNames, "IP地址", "")
Dim $SetSubnetmask[1]
$SetSubnetmask[0] = IniRead($dir, $SectionNames, "子网掩码", "")
Dim $SetGateway[1]
$SetGateway[0] = IniRead($dir, $SectionNames, "网关地址", "")
Dim $SetDns[2]
$SetDns[0] = IniRead($dir, $SectionNames, "首选DNS", "")
$SetDns[1] = IniRead($dir, $SectionNames, "备用DNS", "")
TrayTip("", "正在设置IP,请稍等...", 1)
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 0x10 + 0x20)
$colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
If IsObj($colItems) Then
For $objNetAdapter In $colItems
$objNetAdapter.EnableStatic($SetIPAddress, $SetSubnetmask)
$objNetAdapter.SetGateways($SetGateway)
$objNetAdapter.SetDNSServerSearchOrder($SetDns)
Next
EndIf
$ComputerName = IniRead($dir, $SectionNames, "计算机名称", "")
$SetIPX = IniRead($dir, $SectionNames, "内部网络号IPX", "")
$SetIPX = Dec($SetIPX)
$ServIP = IniRead($dir, $SectionNames, "网维服务器IP", "")
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName", "ComputerName", "REG_SZ", $ComputerName)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $ComputerName)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $ComputerName)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ", $ComputerName)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "VirtualNetworkNumber", "REG_DWORD", $SetIPX)
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Nwlnkipx\Parameters", "VirtualNetworkNumber", "REG_DWORD", $SetIPX)
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\iCafe8", "ServIP", "REG_SZ", $ServIP)
Exit
第二种是:(写入IP、掩码、网关部分)
RunWait(@ComSpec & ' /c netsh -c interface ip set address "本地连接" static ' & $xrip & ' 255.255.255.0 ' & $xrwg & ' 1', "", @SW_HIDE)
两种方法都试用过了,第一种感觉太复杂,很多命令都不懂原理,有时候会生效;第二种看起来简单,好像是(呵呵,好像是)使用的命令行吧,但是其中的“掩码”部分:一是不是能用变量,用变量代入同样的值都出错,二是其值只是能"255.255.255.0",若改为"255.255.255.69"也出错。
不知道哪位大侠能腾出宝贵的时间对这两种写入IP的方法的原理予以详解,不胜感激!
[ 本帖最后由 ahphsautoit 于 2009-4-7 14:45 编辑 ] |