找回密码
 加入
搜索
查看: 1711|回复: 3

au3关联按键问题

[复制链接]
发表于 2009-2-14 16:18:11 | 显示全部楼层 |阅读模式
本帖最后由 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
发表于 2009-2-14 16:28:19 | 显示全部楼层
程序运行先设定BUTTON1为默认按钮 BUTTON1的事件处理完吼设定BUTTON2为默认按钮 这不就OK了?
 楼主| 发表于 2009-2-14 16:30:58 | 显示全部楼层

大绯狼

能讲一下具体的实现方法么?

怎么设置默认按钮,还有怎么设置事件传递?
发表于 2009-2-14 17:04:33 | 显示全部楼层
[au3]#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 531, 233, 193, 125)
$Button1 = GUICtrlCreateButton("Button1", 120, 80, 75, 25, 0)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$Button2 = GUICtrlCreateButton("Button2", 280, 72, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        pro()
                        GUICtrlSetState($Button2, $GUI_DEFBUTTON)
                Case $Button2
                        MsgBox(0,0,"按钮2的程序")
        EndSwitch
WEnd

Func pro()
        MsgBox(0, 0, "按钮1的程序")
EndFunc   ;==>pro[/au3]

IP要方便就可以使用_GUICtrlIpAddress_Create

[ 本帖最后由 大绯狼 于 2009-2-14 17:08 编辑 ]
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-5 10:30 , Processed in 0.080304 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表