以下是我对上述英文版的脚本的改写。在我的笔记本上运行通过。
其主要改动在于中间用了发送中文字符“无线”。参考链接:UDF - SendC,作用:发送中文以及其它字符! 。
其他小的改动看内容和注释即可,不解释了。
另外:我也不是很明白为什么ssid变量一定要加括号,否则运行就不成功。- ;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
复制代码 |