我正在尝试通过OS Windows 8中的MSFT_NetAdapter禁用/启用网络适配器。
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=Delegate," _
& "authenticationLevel=pktPrivacy}\root\standardcimv2")
Set colSettings = objWMIService.ExecQuery("Select * from MSFT_NetAdapter")
For Each objOperatingSystem in colSettings
Wscript.Echo _
"DeviceID: " & objOperatingSystem.DeviceID & vbCrLf & _
"Name: " & objOperatingSystem.Name
objOperatingSystem.Disable
Next
例如仅使用禁用。MSFT_NetAdapter返回“DeviceID”或“Name”,当您调用objOperatingSystem.Disable方法时,会出现错误0x80041003“当前用户无权执行该操作”。
我尝试使用以下代码:
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=Delegate," _
& "authenticationLevel=pktPrivacy}\root\cimv2")
Set colSettings = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter where PhysicalAdapter = true")
For Each objOperatingSystem in colSettings
Wscript.Echo _
"DeviceID: " & objOperatingSystem.DeviceID & vbCrLf & _
"Name: " & objOperatingSystem.Name
objOperatingSystem.Disable
Next
这段代码在Windows 7上运行良好。在代码执行后,网络适配器会立即切换。但在Windows 8操作系统中,禁用/启用需要在代码执行后进行系统重启。
如何在Windows 8操作系统中管理网络适配器?