I am looking for a way to use a batch script to turn on or off WLAN connections, but I do not want to require administrator privileges to do so.
However, I have discovered that it is possible to achieve this using the graphical user interface (GUI):
I have been unable to locate a method for accomplishing this task through the command prompt (cmd) that is identical to what I am looking for. The only solutions I have found involve enabling or disabling the network adapter or something similar, which requires administrative privileges.
I would appreciate any assistance with this matter.
2 Answers
Introduction
Wireless Local Area Network (WLAN) connections are a common way of connecting to the internet wirelessly. Sometimes, you may want to enable or disable your WLAN connections using a batch script. However, the problem is that you may not want to require admin privileges. In this blog post, we will discuss ways to enable/disable WLAN connections using a batch script without admin privileges.
Method 1: Using netsh command
One of the ways to enable/disable WLAN connections using a batch script without admin privileges is by using the netsh command. The netsh command is a command-line utility that allows you to display or modify the network configuration of a computer. To enable/disable WLAN connections using the netsh command, follow these steps:
1. Open Notepad or any text editor.
2. Type the following command in the text editor:
netsh interface set interface "Wireless Network Connection" admin=disable
3. Replace “Wireless Network Connection” with the name of your WLAN adapter. You can find the name of your WLAN adapter by running the following command in the command prompt:
netsh interface show interface
4. Save the file with a .bat extension.
5. Double-click the .bat file to run it.
This will disable your WLAN connection. To enable your WLAN connection, replace “disable” with “enable” in the command.
Method 2: Using PowerShell
Another way to enable/disable WLAN connections using a batch script without admin privileges is by using PowerShell. PowerShell is a task automation and configuration management framework from Microsoft. To enable/disable WLAN connections using PowerShell, follow these steps:
1. Open Notepad or any text editor.
2. Type the following command in the text editor:
Get-NetAdapter -Name "Wireless Network Connection" | Disable-NetAdapter
3. Replace “Wireless Network Connection” with the name of your WLAN adapter. You can find the name of your WLAN adapter by running the following command in PowerShell:
Get-NetAdapter
4. Save the file with a .ps1 extension.
5. Open PowerShell and navigate to the directory where the .ps1 file is saved.
6. Run the .ps1 file by typing its name and pressing Enter.
This will disable your WLAN connection. To enable your WLAN connection, replace “Disable” with “Enable” in the command.
Method 3: Using WMI
Another way to enable/disable WLAN connections using a batch script without admin privileges is by using Windows Management Instrumentation (WMI). WMI is a set of extensions to the Windows Driver Model that provides an operating system interface through which instrumented components can provide information and notification. To enable/disable WLAN connections using WMI, follow these steps:
1. Open Notepad or any text editor.
2. Type the following command in the text editor:
wmic path win32_networkadapter where "Name='Wireless Network Connection'" call disable
3. Replace “Wireless Network Connection” with the name of your WLAN adapter. You can find the name of your WLAN adapter by running the following command in the command prompt:
wmic nic get name, index
4. Save the file with a .bat extension.
5. Double-click the .bat file to run it.
This will disable your WLAN connection. To enable your WLAN connection, replace “disable” with “enable” in the command.
Method 4: Using DevCon
DevCon is a command-line tool that displays detailed information about devices, and lets you disable, enable, and uninstall devices. To enable/disable WLAN connections using DevCon, follow these steps:
1. Download DevCon from Microsoft’s website and extract it to a folder.
2. Open Notepad or any text editor.
3. Type the following command in the text editor:
devcon disable "PCIVEN_8086&DEV_08B1&SUBSYS_40708086"
4. Replace “PCIVEN_8086&DEV_08B1&SUBSYS_40708086” with the Device ID of your WLAN adapter. You can find the Device ID of your WLAN adapter by running the following command in the command prompt:
devcon findall * | find /i "Wireless Network Connection"
5. Save the file with a .bat extension.
6. Double-click the .bat file to run it.
This will disable your WLAN connection. To enable your WLAN connection, replace “disable” with “enable” in the command.
Method 5: Using Task Scheduler
Another way to enable/disable WLAN connections using a batch script without admin privileges is by using Task Scheduler. Task Scheduler is a component of Microsoft Windows that provides the ability to schedule the launch of programs or scripts at pre-defined times or after specified time intervals. To enable/disable WLAN connections using Task Scheduler, follow these steps:
1. Open Task Scheduler.
2. Click on “Create Task” in the “Actions” panel.
3. Give the task a name and description.
4. Click on the “Triggers” tab and click “New”.
5. Choose the schedule you want for the task and click “OK”.
6. Click on the “Actions” tab and click “New”.
7. Choose “Start a program” as the action.
8. In the “Program/script” field, enter the path to the batch file.
9. Click “OK” to save the action.
10. Click “OK” to save the task.
This will schedule your batch file to run at the specified time and enable/disable your WLAN connection.
Conclusion
Enabling/disabling WLAN connections using a batch script without admin privileges is possible using various methods such as netsh command, PowerShell, WMI, DevCon, and Task Scheduler. These methods are simple and easy to use, and they allow you to quickly enable/disable your WLAN connections without having to go through the GUI. Choose the method that works best for you and enjoy the convenience of enabling/disabling WLAN connections with just a few clicks.
At present, the most effective solution is the one suggested in the comment by @somebadhat.
They recommend using a .vbs script available on a particular website for Windows 7, which can enable or disable the network adapter. Unfortunately, this method does require administrator permissions, and you will receive a UAC prompt. If there is a better solution available, please update this community wiki accordingly.
Since I have a German-language PC, I had to modify the script by changing “En&able
” to “&Aktivieren
” and “Disa&ble
” to “&Deaktivieren
“. You can change it back to the original if needed.
I also changed the adapter name to “WLAN
” in my version of the script.
'~ Toggle a SPECIFIED NIC on or off
Option Explicit
Const NETWORK_CONNECTIONS = &H31&
Dim objShell, objFolder, objFolderItem, objEnable, objDisable, wshShell
Dim folder_Object, target_NIC
Dim NIC, clsVerb
Dim str_NIC_Name, strEnable, strDisable
Dim bEnabled, bDisabled
' ========================================================
' ===== place the name of your network adapter here ======
' examples:
' str_NIC_Name = "Local Area Connection 2"
' str_NIC_Name = "Wireless Connection 1"
' ========================================================
str_NIC_Name = "WLAN"
' ========================================================
strEnable = "&Aktivieren"
strDisable = "&Deaktivieren"
' create objects and get items
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(NETWORK_CONNECTIONS)
Set objFolderItem = objFolder.Self
Set folder_Object = objFolderItem.GetFolder
' see if the namespace exists
If folder_Object Is Nothing Then
Wscript.Echo "Could not find Network Connections"
WScript.Quit
End If
Set target_NIC = Nothing
' look at each NIC and match to the chosen name
For Each NIC In folder_Object.Items
If LCase(NIC.Name) = LCase(str_NIC_Name) Then
' proper NIC is found, get it
Set target_NIC = NIC
End If
Next
If target_NIC Is Nothing Then
WScript.Echo "Unable to locate proper NIC"
WScript.Quit
End If
bEnabled = True
Set objEnable = Nothing
Set objDisable = Nothing
For Each clsVerb In target_NIC.Verbs
'~ Wscript.Echo clsVerb
If clsVerb.Name = strEnable Then
Set objEnable = clsVerb
bEnabled = False
'~ WScript.Echo "enable"
End If
If clsVerb.Name = strDisable Then
Set objDisable = clsVerb
'~ WScript.Echo "disable"
End If
Next
Set wshShell = CreateObject( "WScript.Shell" )
If bEnabled Then
WScript.Echo "disable"
objDisable.DoIt
Else
WScript.Echo "enable"
objEnable.DoIt
End If
wshShell.Run "ms-settings:network-proxy"
'~ Give the connection time to stop/start, prompt after UAC prompt
WScript.Sleep 1000
WScript.Echo "end"
WScript.Quit