Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vbscript 运行VBS文件时,Microsoft是否更改NetConnectionID的名称?_Vbscript - Fatal编程技术网

Vbscript 运行VBS文件时,Microsoft是否更改NetConnectionID的名称?

Vbscript 运行VBS文件时,Microsoft是否更改NetConnectionID的名称?,vbscript,Vbscript,下面的代码禁用本地连接并启用无线连接,它以前工作得很好 最近我的Windows7和64更新,我发现代码不工作,为什么 顺便说一句,我想微软可能会更改NetConnectionID的名称,但我不确定 my.vbs Set WMI=GetObject("winmgmts:\\.\root\cimv2") Set w=WMI.ExecQuery("select * from WIN32_NetworkAdapter") For Each i In w If i.NetConnectionID="

下面的代码禁用本地连接并启用无线连接,它以前工作得很好

最近我的Windows7和64更新,我发现代码不工作,为什么

顺便说一句,我想微软可能会更改NetConnectionID的名称,但我不确定

my.vbs

Set WMI=GetObject("winmgmts:\\.\root\cimv2")
Set w=WMI.ExecQuery("select * from WIN32_NetworkAdapter")
For Each i In w
   If i.NetConnectionID="本地连接" Then     
      i.Disable()    
   End If
  If i.NetConnectionID="无线网络连接" Then     
      i.Enable()    
   End If
next

WScript.Sleep  3000 

CreateObject("WScript.Shell").run "netsh wlan connect name=weiiPhone6",0
修改代码

Dim retValue

Set WMI=GetObject("winmgmts:\\.\root\cimv2")
Set w=WMI.ExecQuery("select * from WIN32_NetworkAdapter")
For Each i In w
   If i.NetConnectionID="本地连接" Then     
      retValue = i.Disable()    
   End If
   If i.NetConnectionID="无线网络连接" Then     
      retValue = i.Enable()    
   End If
   If retValue <> 0 Then
      'Check return value for the specific error.
      MSGBOX retValue
   End If
   retValue = 0
Next

WScript.Sleep  3000 

CreateObject("WScript.Shell").run "netsh wlan connect name=weiiPhone6",0
Dim-retValue
设置WMI=GetObject(“winmgmts:\\.\root\cimv2”)
Set w=WMI.ExecQuery(“从WIN32\U NetworkAdapter中选择*)
对于w中的每个i
如果i.NetConnectionID=”本地连接" 然后
retValue=i.Disable()
如果结束
如果i.NetConnectionID=”无线网络连接”“那么
retValue=i.Enable()
如果结束
如果值为0,则
'检查特定错误的返回值。
MSGBOX retValue
如果结束
retValue=0
下一个
WScript.sleep3000
CreateObject(“WScript.Shell”)。运行“netsh wlan connect name=weiiPhone6”,0

这可能是由于未使用提升的权限运行脚本。如果您确信正在运行
If
语句,请尝试检查
Enable()
Disable()
方法的返回值

Dim-retValue
设置WMI=GetObject(“winmgmts:\\.\root\cimv2”)
Set w=WMI.ExecQuery(“从WIN32\U NetworkAdapter中选择*)
对于w中的每个i
如果i.NetConnectionID=”本地连接”“那么
retValue=i.Disable()
如果结束
如果i.NetConnectionID=”无线网络连接”“那么
retValue=i.Enable()
如果结束
如果值为0,则
'检查特定错误的返回值。
如果结束
retValue=0
下一个
WScript.sleep3000
CreateObject(“WScript.Shell”)。运行“netsh wlan connect name=weiiPhone6”,0

有用的链接

现在,我测试了.I.NetConnectionID=”本地连接“是的,看起来i.Disable()和i.Enable()是不要启动!可能Windows 7操作系统阻止vbs以启用或取消网络连接,但我已关闭Microsoft Security Essentials和Windows Defender!谢谢!请您查看我修改的代码,retValue display 5,我不知道是什么意思!@HelloCW@HelloCW您会发现系统错误代码5是Access Denied。所以,它似乎是我在回答中建议的权限。只需在Google中查找Windows错误代码5。我必须创建一个快捷方式,就像C:\Windows\System32\wscript.exe C:\Users\cuiwei\Desktop\Other\DisConnect\u V3.vbs一样,并以管理员身份运行它,通过右键单击鼠标选择该项目,它太复杂了,无法理解它为什么会工作d以前很好,但目前它需要管理员角色