the Wireless Network Connection
WinWait ( 'Network Connections')
if NOT WinActive ( 'Network Connections') then
WinActivate ( 'Network Connections')
endif
WinWaitActive ( 'Network Connections')
Send('wireless')
send ('{Appskey}')
send ( 'r' )
这段如果换成中文名称后,就无法找到无线网络连接。因为在英文版下是可以通过键盘来定位到wireless连接上,由于中文版默认安装好后都为“无线网络连接”,请问除了改为英文名称还有什么办法可以通过键盘定位到无线网络连接上! 在中文的上面估计有点问题
the Wireless Network Connection
WinWait ( 'Network Connections')
if NOT WinActive ( 'Network Connections') then
WinActivate ( 'Network Connections')
endif
WinWaitActive ( 'Network Connections')
Send('wireless')
send ('{Appskey}')
send ( 'r' )
这段如果换成中文名称后,就无法找到无线网络连接。因为在英文版下是可以通过键盘来定位到wireless连接上,由于中文版默认安装好后都为“无线网络连接”,请问除了改为英文名称还有什么办法可以通过键盘定位到无线网络连接上! 是的,我改过一些,测试通过。有时间把字符串全改了在我笔记本上再试试看。不好意思现在公司只用台式机。 以下是我对上述英文版的脚本的改写。在我的笔记本上运行通过。
其主要改动在于中间用了发送中文字符“无线”。参考链接: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
对了,若干次里会有1,2次不成功,不妨在47,58行再插入一行sleep(500)试试看。但是不成功也没关系,多运行几次罢了。
所以有种比较猥琐的解决方案:就是把代码复制两次,再编译成exe。。。。。。 非常感谢你的解答! 谢谢提供,正好要用。 看看我的代码,这样就不会出现偶尔设置不了的情况:
1。如果无线网络被禁用,则启用
2。打开设置窗口
;无线网络
Dim $objShell,$objFolder,$objFolderItem,$objVerb
$objShell=ObjCreate('Shell.Application')
$objFolder=$objShell.NameSpace("::{7007ACC7-3202-11D1-AAD2-00805FC1270E}")
For $index = 0 To $objFolder.Items.Count-1 Step 1
$objFolderItem = $objFolder.Items.Item($index)
If $objFolderItem.Name='无线网络连接' Then
For $index2 = 0 To $objFolderItem.Verbs.Count-1 Step 1
If $objFolderItem.Verbs.Item($index2).Name='启用(&A)' Then
$objFolderItem.Verbs.Item($index2).DoIt
WinWaitClose('无线网络连接','启用')
Sleep(3000)
EndIf
Next
For $index2 = 0 To $objFolderItem.Verbs.Count-1 Step 1
If $objFolderItem.Verbs.Item($index2).Name='查看可用的无线连接(&V)' Then
$objFolderItem.Verbs.Item($index2).DoIt
EndIf
Next
EndIf
Next
页:
1
[2]