找回密码
 加入
搜索
楼主: haha_xion

请教:利用脚本添加无线配置问题

[复制链接]
 楼主| 发表于 2009-11-5 11:17:23 | 显示全部楼层
在中文的上面估计有点问题
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连接上,由于中文版默认安装好后都为“无线网络连接”,请问除了改为英文名称还有什么办法可以通过键盘定位到无线网络连接上!
 楼主| 发表于 2009-11-5 11:19:15 | 显示全部楼层
在中文的上面估计有点问题
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连接上,由于中文版默认安装好后都为“无线网络连接”,请问除了改为英文名称还有什么办法可以通过键盘定位到无线网络连接上!
发表于 2009-11-5 11:37:24 | 显示全部楼层
是的,我改过一些,测试通过。有时间把字符串全改了在我笔记本上再试试看。不好意思现在公司只用台式机。
发表于 2009-11-5 23:03:43 | 显示全部楼层
以下是我对上述英文版的脚本的改写。在我的笔记本上运行通过。

其主要改动在于中间用了发送中文字符“无线”。参考链接:UDF - SendC,作用:发送中文以及其它字符!

其他小的改动看内容和注释即可,不解释了。

另外:我也不是很明白为什么ssid变量一定要加括号,否则运行就不成功。
  1. ;Assign variables
  2. $ssid = ("SSID")
  3. $auth = ("WPA-PSK");共有四种模式
  4. $encrypt = ("TKIP");对应WPA-PSK的有两种
  5. $NetKey = ("password")

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

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

  14. Sendc("无线")

  15. Send('{Appskey}')
  16. Send('r')

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

  27. ;Insure the Wireless Networks tab has focus
  28. WinWait($hwnd, "无线网络")
  29. If Not WinActive($hwnd, "无线网络") Then
  30.         WinActivate($hwnd, "无线网络")
  31. EndIf
  32. WinWaitActive($hwnd, "无线网络")
  33. Sleep(500)

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

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

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

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

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

  60. ;发送中文字符串的程序
  61. Func SendC($Str, $Flag = 0)
  62.         If $Flag Then
  63.                 Local $Clip = ClipGet()
  64.                 ClipPut($Str)
  65.                 Send('+{ins}')
  66.                 ClipPut($Clip)
  67.         Else
  68.                 Local $Nul = Chr(0)
  69.                 For $i = 1 To StringLen($Str)
  70.                         Send('{ASC ' & StringToBinary(StringMid($Str, $i, 1) & $Nul) & '}')
  71.                 Next
  72.         EndIf
  73. EndFunc   ;==>SendC
复制代码
发表于 2009-11-5 23:58:06 | 显示全部楼层
对了,若干次里会有1,2次不成功,不妨在47,58行再插入一行sleep(500)试试看。但是不成功也没关系,多运行几次罢了。







所以有种比较猥琐的解决方案:就是把代码复制两次,再编译成exe。。。。。。
 楼主| 发表于 2009-11-6 23:52:04 | 显示全部楼层
非常感谢你的解答!
发表于 2009-12-2 09:02:59 | 显示全部楼层
谢谢提供,正好要用。
发表于 2009-12-9 09:11:11 | 显示全部楼层
看看我的代码,这样就不会出现偶尔设置不了的情况:
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
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2026-9-21 19:51 , Processed in 0.054426 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

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