Board logo

标题: [网络连接] 无线网络连接与本地连接的网卡禁用启用切换 能不能让无线网卡自动连接信号源呀? [打印本页]

作者: sblisb    时间: 2013-4-18 10:50     标题: 无线网络连接与本地连接的网卡禁用启用切换 能不能让无线网卡自动连接信号源呀?

找到如下代码,问题是本地连接网卡禁用,而无线网卡启用后,无线连接不会自动连接,要手动选一下连接
而如果是手操作的话,无线网卡会自动找到无线网络“lh2”信号接入,
能不能做到呢?
  1. ********以下是"Run-WirelessConnection.vbs"的代码(我只是分割线 不包括我)********
  2. sEnableConnectionName = "无线网络连接"
  3. sDisableConnectionName = "本地连接"
  4. Const ssfCONTROLS = 3
  5. sEnableVerb = "启用(&A)"
  6. sDisableVerb = "停用(&B)"
  7. set shellApp = createobject("shell.application")
  8. set oControlPanel = shellApp.Namespace(ssfCONTROLS)
  9. set oNetConnections = nothing
  10. for each folderitem in oControlPanel.items
  11.    If folderitem.name   = "网络连接" Then
  12.      Set oNetConnections = folderitem.getfolder: exit for
  13.    end if
  14. next
  15. if oNetConnections is nothing then
  16.    msgbox "未找到网络和拨号连接文件夹"
  17.    wscript.quit
  18. end if
  19. '-----------------停用连接--------------------------
  20. set oLanConnection = nothing
  21. for each folderitem in oNetConnections.items
  22.    if lcase(folderitem.name)   = lcase(sDisableConnectionName) then
  23.      set oLanConnection = folderitem: exit for
  24.    end if
  25. next
  26. if oLanConnection is nothing then
  27.    msgbox "未找到 '" & sDisableConnectionName & "' item"
  28. Else
  29.    Set oEnableVerb = nothing
  30.    set oDisableVerb = nothing
  31.    For each verb in oLanConnection.verbs
  32.      if verb.name = sDisableVerb then  
  33.        set oDisableVerb = verb
  34.        Exit For
  35.      end if
  36.    next
  37.   
  38.    If not (oDisableVerb is nothing) then
  39.      oDisableVerb.DoIt
  40.    end if
  41. end If
  42. '---------------------------启用连接---------------------------------
  43. set oLanConnection = nothing
  44. for each folderitem in oNetConnections.items
  45.    if lcase(folderitem.name)   = lcase(sEnableConnectionName) then
  46.      set oLanConnection = folderitem: exit for
  47.    end if
  48. next
  49. if oLanConnection is nothing then
  50.    msgbox "未找到 '" & sEnableConnectionName & "' item"
  51. Else
  52.    Set oEnableVerb = nothing
  53.    set oDisableVerb = nothing
  54.    For each verb in oLanConnection.verbs
  55.      If verb.name = sEnableVerb then  
  56.        set oEnableVerb = verb
  57.        Exit For
  58.      End if
  59.    next
  60.   
  61.    If not (oEnableVerb is nothing) then
  62.      oEnableVerb.DoIt
  63.    end if
  64. end If
  65. wscript.sleep 800
  66. ********以下是"Run-LocalConnection.vbs"的代码(我只是分割线 不包括我)********
  67. sEnableConnectionName = "本地连接"
  68. sDisableConnectionName = "无线网络连接"
  69. Const ssfCONTROLS = 3
  70. sEnableVerb = "启用(&A)"
  71. sDisableVerb = "停用(&B)"
  72. set shellApp = createobject("shell.application")
  73. set oControlPanel = shellApp.Namespace(ssfCONTROLS)
  74. set oNetConnections = nothing
  75. for each folderitem in oControlPanel.items
  76.    If folderitem.name   = "网络连接" Then
  77.      Set oNetConnections = folderitem.getfolder: exit for
  78.    end if
  79. next
  80. if oNetConnections is nothing then
  81.    msgbox "未找到网络和拨号连接文件夹"
  82.    wscript.quit
  83. end if
  84. '-----------------停用连接--------------------------
  85. set oLanConnection = nothing
  86. for each folderitem in oNetConnections.items
  87.    if lcase(folderitem.name)   = lcase(sDisableConnectionName) then
  88.      set oLanConnection = folderitem: exit for
  89.    end if
  90. next
  91. if oLanConnection is nothing then
  92.    msgbox "未找到 '" & sDisableConnectionName & "' item"
  93. Else
  94.    Set oEnableVerb = nothing
  95.    set oDisableVerb = nothing
  96.    For each verb in oLanConnection.verbs
  97.      if verb.name = sDisableVerb then  
  98.        set oDisableVerb = verb
  99.        Exit For
  100.      end if
  101.    next
  102.   
  103.    If not (oDisableVerb is nothing) then
  104.      oDisableVerb.DoIt
  105.    end if
  106. end If
  107. '---------------------------启用连接---------------------------------
  108. set oLanConnection = nothing
  109. for each folderitem in oNetConnections.items
  110.    if lcase(folderitem.name)   = lcase(sEnableConnectionName) then
  111.      set oLanConnection = folderitem: exit for
  112.    end if
  113. next
  114. if oLanConnection is nothing then
  115.    msgbox "未找到 '" & sEnableConnectionName & "' item"
  116. Else
  117.    Set oEnableVerb = nothing
  118.    set oDisableVerb = nothing
  119.    For each verb in oLanConnection.verbs
  120.      If verb.name = sEnableVerb then  
  121.        set oEnableVerb = verb
  122.        Exit For
  123.      End if
  124.    next
  125.   
  126.    If not (oEnableVerb is nothing) then
  127.      oEnableVerb.DoIt
  128.    end if
  129. end If
  130. wscript.sleep 800
  131. ********以下是"启用 Wireless.bat"的代码(我只是分割线 不包括我)********
  132. @echo off
  133. rem ***************Wireless Zero Configuration
  134. @echo.
  135. sc config WZCSVC start= demand
  136. @echo.
  137. sc start "WZCSVC"
  138. rem ***************Atheros 配置服务
  139. @echo.
  140. sc config ACS start= demand
  141. @echo.
  142. sc start "ACS"
  143. start Run-WirelessConnection.vbs
  144. ********以下是"启用 本地连接.bat"的代码(我只是分割线 不包括我)********
  145. @echo off
  146. start Run-LocalConnection.vbs
  147. rem ***************Wireless Zero Configuration
  148. @echo.
  149. sc config WZCSVC start= disabled
  150. @echo.
  151. sc stop "WZCSVC"
  152. rem ***************Atheros 配置服务
  153. @echo.
  154. sc config ACS start= disabled
  155. @echo.
  156. sc stop "ACS"
复制代码

作者: sblisb    时间: 2013-4-28 09:52

晕死,用了这个无线手工都连不上了,出现如下错误

后来用如下办法以解决,求能用的切换无线网络和有线网络的代码,谢谢
http://support.microsoft.com/kb/871122/zh-cn

在更新到 Windows XP Service Pack 2 或 Windows XP Tablet PC Edition 2005 之后尝试运行无线网络安装向导时出现错误消息
察看本文应用于的产品
文章编号 : 871122
最后修改 : 2008年8月15日
修订 : 3.0
简介
无线网络安装向导和“查看可用的无线网络”功能都依赖于无线零配置服务来提供针对 Microsoft Windows XP Service Pack 2 (SP2) 和 Microsoft Windows XP Table PC Edition 2005 的功能。如果无线零配置服务不可用,您可能会收到一条错误消息,指示您转到本文章。

回到顶端
更多信息
之所以发生此行为,可能是由于以下几种原因。某些计算机和硬件制造商提供了自己的配置软件,替代了 Windows 中提供的无线零配置服务。这种情况下,必须使用该制造商提供的软件来配置无线网络。如果要使用无线网络安装向导或“查看可用的无线网络”功能来配置无线设备,请参阅您的计算机或无线网卡附带的文档。使用本文档可以确定是否能够使用无线零配置服务来配置无线网络。有时,您无法使用 Windows 功能。

如果您的计算机或无线网络适配器没有附带自己的无线网络软件,请按照下列步骤操作:
1. 单击“开始”,单击“运行”,键入 ncpa.cpl,然后单击“确定”。
2. 单击“网络连接”。
3. 在“网络连接”中,单击以选择您的无线连接,然后单击“更改此连接的设置”。
4. 在“无线网络”选项卡中,单击以选择“用 Windows 配置我的无线网络设置”复选框。

要启动无线零配置服务,请按照下列步骤操作:
1. 单击“开始”,单击“运行”,键入 %SystemRoot%\\system32\\services.msc /s,然后单击“确定”。
2. 双击“Wireless Zero Configuration”。
3. 在“启动类型”列表中,单击“自动”,然后单击“应用”。
4. 在“服务状态”区域下,单击“启动”,然后单击“确定”。

如果在尝试启动此服务时收到错误消息,请参阅“参考”部分以获得详细的故障排除信息





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2