fuinei 发表于 2012-3-24 11:27:15

使用脚本自动完成无线配置的问题

各位好,我参考论坛中的贴子测试使用脚本自动完成无线配置时遇到一个问题,由于测试机上有2张无线网卡最终导致无法定位到"无线网络连接"并打开属性窗口的问题,请问各位有没有什么好方法可以解决这个问题呢?
注:
1、2张无线网卡的名称分别为"无线网络连接"和"无线网络连接 2"
2、需配置的网卡名称为"无线网络连接"
3、原始帖子链接如下:
http://autoitx.com/forum.php?mod=viewthread&tid=10657&highlight=%CE%DE%CF%DF%C5%E4
参考代码:;Assign variables
$ssid = ("SSID")
$auth = ("WPA-PSK");共有四种模式
$encrypt = ("TKIP");对应WPA-PSK的有两种
$NetKey = ("password")

; Setting the advanced setting in Network Properties
Run(@ComSpec & " /c " & 'ncpa.cpl', "C:\WINDOWS\system32\dllcache", @SW_HIDE)

;Open the Network Connections dialog and activate the properties page of the Wireless Network Connection
WinWait("网络连接")
If Not WinActive("网络连接") Then
      WinActivate("网络连接")
EndIf
WinWaitActive("网络连接")

Sendc("无线")

Send('{Appskey}')
Send('r')

;Insure the Wireless Network Connection Properties page has focus and move to the appropriate tab
$hwnd = WinGetHandle("无线网络连接 属性")
WinWait($hwnd, "常规")
If Not WinActive($hwnd, "常规") Then
      WinActivate($hwnd, "常规")
EndIf
WinWaitActive($hwnd, "常规")
Sleep(500)
ControlCommand($hwnd, "常规", 12320, 'TabRight', '')
Sleep(500)

;Insure the Wireless Networks tab has focus
WinWait($hwnd, "无线网络")
If Not WinActive($hwnd, "无线网络") Then
      WinActivate($hwnd, "无线网络")
EndIf
WinWaitActive($hwnd, "无线网络")
Sleep(500)

;Check to insure that Windows Wireless Zero Configuration is being used, then click on the Add button
If Not ControlCommand($hwnd, "无线网络", 7024, 'IsChecked', '') Then
      ControlCommand($hwnd, "无线网络", 7024, 'Check', '')
EndIf
ControlFocus($hwnd, "无线网络", 7033)
Sleep(500)
ControlClick($hwnd, "", 'Button7')

;Input the Wireless network properties information and save it
$handle = WinGetHandle("无线网络属性")
ControlSetText($handle, "关联", "Edit1", $ssid)
ControlCommand($handle, "网络验证", "ComboBox1", "SelectString", $auth)
ControlCommand($handle, "数据加密", "ComboBox2", "SelectString", $encrypt)
ControlSetText($handle, "网络密钥", "Edit2", $NetKey)
ControlSetText($handle, "确认网络密钥", "Edit3", $NetKey)
ControlClick($handle, "", "Button4")

;Close the Wireless Network Connection Properties window
;没有起作用,因此我把它注释掉
;~ If WinExists("无线网络属性") Then
;~         WinActivate("无线网络属性")
;~         ControlFocus("无线网络属性", "无线网络", 1)
;~         ControlClick("无线网络属性", "无线网络", 1)
;~ EndIf

ControlClick($hwnd, "", 'Button11')

;Close the Network Connections windows
WinActivate("网络连接")
Send('!{F4}')

;发送中文字符串的程序
Func SendC($Str, $Flag = 0)
      If $Flag Then
                Local $Clip = ClipGet()
                ClipPut($Str)
                Send('+{ins}')
                ClipPut($Clip)
      Else
                Local $Nul = Chr(0)
                For $i = 1 To StringLen($Str)
                        Send('{ASC ' & StringToBinary(StringMid($Str, $i, 1) & $Nul) & '}')
                Next
      EndIf
EndFunc   ;==>SendC

502762378 发表于 2012-3-24 16:18:10

又是Button又是ComboBox的实在没精力一一对照检查,相信一些设置的问题可以注册表解决,顺便学习了一条命令行连接无线路由的代码,加上WMI判断网卡名,机器么办法帮你测试希望对你有帮助
#include <Process.au3>
$strComputer = "localhost"
$password = "test";连接无线网络的密码

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", 48)
   For $objItem In $colItems
       If $objItem.Manufacturer = "broadcom" And   $objItem.NetConnectionID= "无线网络连接" Then ;判断无线网络连接并且网卡名称名称为无线网络连接
                   _RunDOS("netsh wlan set hostednetwork mode=allow ssid=无线网络连接 key="&$password)
           EndIf
   Next

fuinei 发表于 2012-3-24 23:11:21

谢谢502762378兄的指导,通过命令操作确实是一个很好的方法,但netsh wlan命令只有win7/2008才能使用,测试机环境为WinXP SP3,所以无法通过命令来实现
页: [1]
查看完整版本: 使用脚本自动完成无线配置的问题