找回密码
 加入
搜索
查看: 2446|回复: 7

帮我看看这个错误怎样解决

[复制链接]
发表于 2008-10-7 12:02:29 | 显示全部楼层 |阅读模式
#include <GuiIPAddress.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <IPAddressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("IP", 213, 182, 193, 115)
$Group1 = GUICtrlCreateGroup("IP设置", 0, 0, 209, 177)
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 72, 24, 130, 21)
_GUICtrlIpAddress_Set($IPAddress1, "127.0.0.1")
$IPAddress2 = _GUICtrlIpAddress_Create($Form1, 72, 48, 130, 21)
_GUICtrlIpAddress_Set($IPAddress2, "255.255.255.0")
$IPAddress3 = _GUICtrlIpAddress_Create($Form1, 72, 72, 130, 21)
_GUICtrlIpAddress_Set($IPAddress3, "0.0.0.0")
$IPAddress4 = _GUICtrlIpAddress_Create($Form1, 72, 96, 130, 21)
_GUICtrlIpAddress_Set($IPAddress4, "0.0.0.0")
$IPAddress5 = _GUICtrlIpAddress_Create($Form1, 72, 120, 130, 21)
_GUICtrlIpAddress_Set($IPAddress5, "0.0.0.0")
$Label1 = GUICtrlCreateLabel(" I P  地 址:", 6, 24, 67, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("子网掩码:", 8, 48, 64, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("默认网关:", 9, 72, 64, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("首选DNS:", 6, 96, 69, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("备用DNS:", 6, 120, 69, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("确定", 72, 147, 59, 25, 0)
$Button2 = GUICtrlCreateButton("取消", 144, 147, 59, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        $ip=_GUICtrlIpAddress_Get($IPAddress1)
                        $sunmask=_GUICtrlIpAddress_Get($IPAddress2)
                        $gateway=_GUICtrlIpAddress_Get($IPAddress3)
                        $PDNS=_GUICtrlIpAddress_Get($IPAddress4)
                        $BDNS=_GUICtrlIpAddress_Get($IPAddress5)
                        ;MsgBox(0,"",$IP)
                       
                        $strComputer="."                       
                        $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
                        $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL")
                        $colComputers = $objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
                        If IsObj($colItems) Then
                                For $objNetAdapter In $colItems
                                        $objNetAdapter.EnableStatic($ip,$sunmask)
                                        $objNetAdapter.SetGateways($gateway)
                                        $objNetAdapter.SetDNSServerSearchOrder($PDNS)
                                Next
                        EndIf
                        MsgBox(0,"","设置完成")               
                       
        EndSwitch
WEnd



运行里提示错误:
>"D:\autoit3\SciTe\ACNWrapper\ACNWrapper.exe" /run /ErrorStdOut /in "D:\2\autoit\学习\ip控件的应用.au3" /autoit3dir "D:\autoit3" /UserParams   
+>11:51:17 开始执行 ACNWrapper v.1.10.1.8
+>执行环境:
+>        系统语言:        0804
+>        键盘布局:        00000804
+>        操作系统:        WIN_2003/Service Pack 2
+>        CPU:                X86
+>        IP地址:                10.16.120.8
>运行 AU3Check (1.54.13.0)  开始目录:D:\autoit3
+>11:51:18 AU3Check 结束[CODE]:0
>运行:(3.2.13.6):D:\autoit3\autoit3.exe "D:\2\autoit\学习\ip控件的应用.au3"   
D:\2\autoit\??\ip?????.au3 (57) : ==> ??????(?????).:
$objNetAdapter.SetGateways=$gateway
$objNetAdapter.SetGateways=$gateway^ ERROR
->11:51:20 AutoIT3.exe 完成:[CODE]:1
+>11:51:21 ACNWrapper 完成!
>退出代码: 1    时间: 4.068

[ 本帖最后由 pg1984 于 2008-10-11 10:14 编辑 ]
发表于 2008-10-7 12:09:24 | 显示全部楼层
先不说别的,你那个IP框好像建立的方法不对
发表于 2008-10-7 12:11:02 | 显示全部楼层
$Form2 = GUICreate("XPOPTI-ADSL网络设置", 270, 280, 378, 197, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS))
$hIP = _GUICtrlIpAddress_Create($Form2, 120, 10, 125, 20)
$hDNS1 = _GUICtrlIpAddress_Create($Form2, 120, 52, 125, 20)
$hDNS2 = _GUICtrlIpAddress_Create($Form2, 120, 72, 125, 20)
_GUICtrlIpAddress_Set($hIP, "")
_GUICtrlIpAddress_Set($hDNS1, "")
_GUICtrlIpAddress_Set($hDNS2, "")
_GUICtrlIpAddress_SetRange($hIP, 0, 0, 255)
_GUICtrlIpAddress_SetRange($hDNS1, 0, 1, 254)
_GUICtrlIpAddress_SetRange($hDNS2, 0, 1, 254)
GUICtrlCreateLabel("网络连接IP地址", 20, 12, 85, 17, 0)
GUICtrlCreateLabel("设置DNS 服务器", 20, 33, 85, 17, 0)
GUICtrlCreateLabel("主要DNS 服务器", 20, 55, 85, 17, 0)
GUICtrlCreateLabel("备用DNS 服务器", 20, 76, 85, 17, 0)
GUICtrlCreateLabel("ADSL上网可以不设置参数,设置这些参数", 24, 104, 224, 17, 0)
GUICtrlCreateLabel("主要用于加速启动和浏览加速下面一组数", 24, 128, 220, 17, 0)
GUICtrlCreateLabel("字是个人设置,可自行设置------", 24, 152, 166, 17, 0)
GUICtrlCreateLabel("网络连接IP:192.168.0.1", 56, 176, 140, 17, 0)
GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("首选DNS:208.67.222.222", 56, 200, 149, 17, 0)
GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("备用DNS:208.67.220.220", 56, 224, 149, 17, 0)
GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", 120, 25, 120, 23)
GUICtrlCreateRadio("自动", 128, 32, 48, 17, 0)
GUICtrlSetOnEvent(-1, "hidedns")
_GUICtrlIpAddress_ShowHide($hDNS1, @SW_HIDE)
_GUICtrlIpAddress_ShowHide($hDNS2, @SW_HIDE)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateRadio("手动", 190, 32, 48, 17, 0)
GUICtrlSetOnEvent(-1, "showdns")
$iptodns = GUICtrlCreateButton("确定", 40, 248, 75, 25, 0)
GUICtrlSetOnEvent(-1, "IPaDNS")
GUICtrlCreateButton("放弃", 160, 248, 75, 25, 0)
GUICtrlSetOnEvent(-1, "Form2Close")
GUISetOnEvent($GUI_EVENT_CLOSE, "Form2Close")
这段是我的一个子界面,你对比看看
 楼主| 发表于 2008-10-7 13:34:31 | 显示全部楼层
我调试的时候是没有错误的,而楼上的代码连调试都不能通过,请教!!!
我使用的是系统默认的消息循环模式,楼上使用的是ONENEVT模式,所以不同。
我调试是通过的,只不过程序运行到
$objNetAdapter.EnableStatic($ip,$sunmask)
$objNetAdapter.SetGateways($gateway)
$objNetAdapter.SetDNSServerSearchOrder($PDNS)
这三行代码才发生有错误,应该是语法错误,我找了资料都找不出应该怎样改。不知楼上的能不能帮忙解决????
谢谢
发表于 2008-10-8 03:13:08 | 显示全部楼层
对了,忘了说一句,我指的不是说代码的问题,是获取ip框的值,必须指定变量是一个句柄变量,否则读出来的不是一回事,你可以用msgbox检查一下就知道了,事件循环和onevent本质上没区别的
把$IPAddress1 改为$hIPAddress1

[ 本帖最后由 netegg 于 2008-10-8 03:52 编辑 ]
发表于 2008-10-8 09:47:22 | 显示全部楼层
你对比一下看一看有什么地方不同:

#include <GuiIPAddress.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <IPAddressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("IP", 213, 182, 193, 115)
$Group1 = GUICtrlCreateGroup("IP设置", 0, 0, 209, 177)
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 72, 24, 130, 21)
_GUICtrlIpAddress_Set($IPAddress1, "127.0.0.1")
$IPAddress2 = _GUICtrlIpAddress_Create($Form1, 72, 48, 130, 21)
_GUICtrlIpAddress_Set($IPAddress2, "255.255.255.0")
$IPAddress3 = _GUICtrlIpAddress_Create($Form1, 72, 72, 130, 21)
_GUICtrlIpAddress_Set($IPAddress3, "0.0.0.0")
$IPAddress4 = _GUICtrlIpAddress_Create($Form1, 72, 96, 130, 21)
_GUICtrlIpAddress_Set($IPAddress4, "0.0.0.0")
$IPAddress5 = _GUICtrlIpAddress_Create($Form1, 72, 120, 130, 21)
_GUICtrlIpAddress_Set($IPAddress5, "0.0.0.0")
$Label1 = GUICtrlCreateLabel(" I P  地 址:", 6, 24, 67, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("子网掩码:", 8, 48, 64, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label3 = GUICtrlCreateLabel("默认网关:", 9, 72, 64, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("首选DNS:", 6, 96, 69, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("备用DNS:", 6, 120, 69, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("确定", 72, 147, 59, 25, 0)
$Button2 = GUICtrlCreateButton("取消", 144, 147, 59, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        $wbemFlagReturnImmediately = 0x10
                        $wbemFlagForwardOnly = 0x20
                        $strComputer = "."
                        Dim $SetIPAddress[1]
                        $SetIPAddress[0] = _GUICtrlIpAddress_Get($IPAddress1)
                        Dim $SetSubnetmask[1]
                        $SetSubnetmask[0] = _GUICtrlIpAddress_Get($IPAddress2)
                        Dim $SetGateway[1]
                        $SetGateway[0] = _GUICtrlIpAddress_Get($IPAddress3)
                        Dim $SetDns[2]
                        $SetDns[0] = _GUICtrlIpAddress_Get($IPAddress4)
                        $SetDns[1] = _GUICtrlIpAddress_Get($IPAddress5)
                        $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
                        $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", _
                                        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
                        If IsObj($colItems) Then
                                For $objNetAdapter In $colItems
                                        $objNetAdapter.EnableStatic($SetIPAddress, $SetSubnetmask)
                                        $objNetAdapter.SetGateways($SetGateway)
                                        $objNetAdapter.SetDNSServerSearchOrder($SetDns)
                                Next
                                MsgBox(64, "设置信息", $SetIPAddress[0] & @CRLF & $SetSubnetmask[0] & @CRLF & $SetGateway[0] & @CRLF & $SetDns)
                        EndIf
                Case $Button2
                        Exit
        EndSwitch
WEnd
 楼主| 发表于 2008-10-8 10:46:49 | 显示全部楼层
谢谢!!
现在终于知道了错在那里了,原来在FOR....IN的时候,只能是对象或者数组。
非常感谢楼上的帮忙!!!
发表于 2008-10-8 13:43:21 | 显示全部楼层
6楼技术很好的!
楼主,问题解决了,应该把提问改成已解决。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-29 01:08 , Processed in 0.075590 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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