Created this VBScript earlier today which will disable all the network adapters on the local computer or enable them depending on the state the adapters are in when the script is run.
https://techish.net/pub/scripts/NetworkSwitch.vbs
' Rich Kreider August 2011 ' Tested to work on Vista/7 - Untested on Windows XP (send reports!) ' Check UAC If WScript.Arguments.length = 0 Then Set objShell = CreateObject("Shell.Application") objShell.ShellExecute "wscript.exe", """" & _ WScript.ScriptFullName & """" &_ " RunAsAdministrator", , "runas", 1 Else ' Set local computer strComputer = "." ' Throw all network adapters that are disabled into a collection Set objWMIService = GetObject("winmgmts:" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_NetworkAdapter Where NetEnabled = 'False'") ' If there are no adapters disabled then lets disable some them! if colItems.count = 0 then MsgBox ("Disabling Internet") ' Since we know there are ZERO disabled adapters, I believe we re-run the select and look ' for all ENABLED adapters so we have something to disable. Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_NetworkAdapter Where NetEnabled = 'True'") ' Loop through all the enabled adapters and disable them (WMI: Win32_NetworkAdapter.Disable() Method) For Each objItem in colItems objItem.Disable Next else ' I guess there were some disabled adapters found, better ' enable them now! MsgBox ("Enabling Internet") For Each objItem in colItems objItem.Enable Next End If End If
Dear Mr Rich Kreider
your scrip that writed for Disable or Enable Network Adapter in Windows with Script:
//////////////////////////////////////////////////////////////////
‘ Check UAC
If WScript.Arguments.length = 0 Then
Set objShell = CreateObject(Shell.Application)
objShell.ShellExecute wscript.exe, & _
WScript.ScriptFullName & &_
RunAsAdministrator, , runas, 1
Else
‘ Set local computer
strComputer = .
‘ Throw all network adapters that are disabled into a collection
Set objWMIService = GetObject(winmgmts: & strComputer & rootCIMV2)
Set colItems = objWMIService.ExecQuery( _
SELECT * FROM Win32_NetworkAdapter Where NetEnabled = ‘False’)
‘ If there are no adapters disabled then lets disable some them!
if colItems.count = 0 then
MsgBox (Disabling Internet)
‘ Since we know there are ZERO disabled adapters, I believe we re-run the select and look
‘ for all ENABLED adapters so we have something to disable.
Set colItems = objWMIService.ExecQuery( _
SELECT * FROM Win32_NetworkAdapter Where NetEnabled = ‘True’)
‘ Loop through all the enabled adapters and disable them (WMI: Win32_NetworkAdapter.Disable() Method)
For Each objItem in colItems
objItem.Disable
Next
else
‘ I guess there were some disabled adapters found, better
‘ enable them now!
MsgBox (Enabling Internet)
For Each objItem in colItems
objItem.Enable
Next
End If
End If
//////////////////////////////////////////////////////////////
it is very good. but I want Do Not Chech UAC .
Please Change it and Send Me .
i will wait…
Very Thanks.
My email address : rhs.bsc@gmail.com
Comment or remove everything between ‘Check Se UAC and
‘Set local computer
I tested it on XP SP3. It pops up a screen asking what user account should execute the program. If I choose my own account it does nothing. And if I uncheck the Protect my computer from … potential dangerous activities.. it gives a error code.
Rule: 17
Mark: 1
Fout: 0x80041021
Code: 80041021
Source: (null)