2

I want to enable/disable WLAN connections using a batch script. The problem is, that I don't want to require admin privileges.

It is possible to change this using the GUI:

GUI without admin

but I didn't find any way to do the exact thing with cmd. I only found ways that enabled/disabled the network adapter or similar that require admin privileges.

Thanks for any help.

  • Add according right to this user via gpedit.msc. User\Templates\Network\Network Connections\Ability to Enable/Disable a LAN connection – Akina Oct 9 '19 at 13:45
  • This program has not been found. Do I need Windows 10 pro/enterprise for this? – dan1st Oct 9 '19 at 13:46
  • You have Home OS (you have not specified)? Try to do it via regedit. HKCU\Software\Policies\Microsoft\Windows\Network Connections, NC_LanChangeProperties=dword:1, do not forget to reboot. And maybe NC_LanProperties=dword:1 additionally. – Akina Oct 9 '19 at 13:49
  • The key is not available and I don't have the permission to create it, even not in HKCU. – dan1st Oct 9 '19 at 13:57
  • @dan1st - What you want is not possible in your current configuration in that case. Given your current configuration enabling WAN would require you to be an Administrator, I assume when you say it's possible in the action center to enable WAN, when you attempt to enable it a UAC prompt appears (you don't specify this to be the fact) but since you are not an Administrator difficult to know for sure anything is true given the lack of detail specfific information about the system – Ramhound Oct 9 '19 at 17:15
0

Currently, the best solution is the following (see the comment from @somebadhat):

The Windows 7 version from this website shows a .vbs script enables/disables the network adapter. Unfortunatly, it requires admin permissions at the end and you have a UAC prompt. If there is a better solution, please edit this community wiki with this.

Because a have a german PC, I needed to change En&able to &Aktivieren and Disa&ble to &Deaktivieren. You may change it back.

Also, I changed the adapter name to WLAN.

My adopted 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
| improve this answer | |
  • It asks me for admin privileges automatically @somebadhat – dan1st Oct 25 '19 at 14:23
  • I did some more work on this and you are right not only does it require admin privileges but I had to create a shortcut to wscript.exe and set it to run as an administrator to get it to work on an account with only standard privileges. wscript.exe.lnk %userprofile%\desktop\DisableEnableWireless.vbs The script will not work with only standard / local / user privileges. – somebadhat Oct 25 '19 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.