本帖最后由 fupsky 于 2009-4-25 16:36 编辑
$py=IniRead("ipset.ini","ipset","py","")
$qz=IniRead("ipset.ini","ipset","qz","")
$ip=IniRead("ipset.ini","ipset","ip","")
$mask=IniRead("ipset.ini","ipset","mask","")
$gateway=IniRead("ipset.ini","ipset","gateway","")
$dns1=IniRead("ipset.ini","ipset","dns1","")
$dns2=IniRead("ipset.ini","ipset","dns2","")
Global $wbemFlagReturnImmediately = 0x10
Global $wbemFlagForwardOnly = 0x20
Global $strComputer = "localhost"
Global $colItems = ""
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 451, 192, 124)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group1 = GUICtrlCreateGroup("", 19, 12, 201, 81)
$hostname=GUICtrlCreateInput("", 91, 30, 75, 21)
$Label1 = GUICtrlCreateLabel("机器名:", 42, 35, 49, 17)
$button1=GUICtrlCreateButton("确定", 91, 59, 75, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("", 19, 104, 201, 200)
$Label2 = GUICtrlCreateLabel("机器名:", 40, 128, 52, 17)
$Label4 = GUICtrlCreateLabel("IP地址:", 40, 147, 50, 17)
$Label6 = GUICtrlCreateLabel("网 关:", 40, 167, 64, 17)
$Label12 = GUICtrlCreateLabel("子网延码:", 29, 187, 64, 17)
$Label8 = GUICtrlCreateLabel("主用DNS:", 35, 215, 64, 17)
$Label10 = GUICtrlCreateLabel("备用DNS:", 35, 235, 64, 17)
$Button2 = GUICtrlCreateButton("确定", 72, 260, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
OKhostname()
case $Button2
xg()
EndSwitch
WEnd
Func OKhostname()
If GUICtrlRead($hostname) = "" Then
MsgBox(0, "MISS的诠释提示:", "请输入机器名!")
Return
ElseIf guictrlread($hostname)+$py>255 Then
MsgBox(0,"错误","您输入的IP地址是"&GUICtrlRead($hostname)+$py&"大于255!请重新配置ipset.ini里的py或者输入小于255的数值!")
Else
GUICtrlCreateLabel($qz&GUICtrlRead($hostname), 96, 128, 100, 17)
GUICtrlCreateLabel($ip&GUICtrlRead($hostname)+$py, 96, 147, 100, 17)
GUICtrlCreateLabel($gateway, 96, 167, 100, 17)
guictrlcreatelabel($mask,96,187,100,17)
GUICtrlCreateLabel($dns1, 96, 215, 100, 17)
GUICtrlCreateLabel($dns2, 96, 235, 100, 17)
EndIf
EndFunc
Func xg()
$SetKey1 = "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\"
$CtrlKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\"
$Return = RegWrite ($SetKey1 & "Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $qz&GUICtrlRead($hostname))
RegWrite ($SetKey1 & "Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $qz&GUICtrlRead($hostname))
RegWrite ($SetKey1 & "Services\Tcpip\Parameters", "Hostname", "REG_SZ", $qz&GUICtrlRead($hostname))
RegWrite ($CtrlKey & "Control\ComputerName\ComputerName", "ComputerName", "REG_SZ", $qz&GUICtrlRead($hostname))
RegWrite ($CtrlKey & "Services\Tcpip\Parameters", "NV Hostname", "REG_SZ", $qz&GUICtrlRead($hostname))
RegWrite ($CtrlKey & "Services\Tcpip\Parameters", "Hostname", "REG_SZ", $qz&GUICtrlRead($hostname))
RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NwlnkIpx\Parameters","VirtualNetworkNumber","REG_DWORD","0x"&GUICtrlRead($hostname))
;修改机器名
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled =TRUE", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
$IPAddress = _ArrayCreate($ip&GUICtrlRead($hostname)+$py)
$SubnetMask = _ArrayCreate($mask)
$GATEWAY = _ArrayCreate($GATEWAY)
$GatewayMetric = _ArrayCreate("1")
If IsObj($colItems) Then
For $objItem In $colItems
$errEnable = $objItem.EnableStatic($IPAddress, $SubnetMask)
$errGateways = $objItem.SetGateways($GATEWAY, $GatewayMetric)
Next
Else
MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_NetworkAdapterConfiguration")
EndIf
;改IP地址
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled =TRUE", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
$DNS = _ArrayCreate($DNS1, $DNS2)
If IsObj($colItems) Then
For $objItem In $colItems
$strDNSServerSearchOrder = $objItem.SetDNSServerSearchOrder($DNS)
Next
Else
MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_NetworkAdapterConfiguration")
EndIf
EndFunc
是一个IP修改工具,我想第一次敲回车的时候处动Button1事件,从而让group2里的label 得到相应的数据,第二次敲回车的时候,处动第二个button,从而修改机器名,IP,网关和DNS
现在的问题是我关联不上回车键,并且,不能很有效的控制机器名的命名规责!如机器名不能为~!@#$%%^&&*(*()(
还有不能控制IP的取值范围,如果192.168.256.200肯定是错的
忘高手给解决一下
ipset.ini的内容是
[ipset]
py=0
qz=A
ip=192.168.1.
mask=255.255.255.0
gateway=192.168.1.1
DNS1=202.99.160.68
DNS2=219.150.32.132 |