Enable/disable WLAN without admin in Windows

7,843

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
Share:
7,843

Related videos on Youtube

dan1st
Author by

dan1st

You may use my whole content of this site (except passages from the corresponding question or passages I stated that are copied from other resources, those underly the conditions of those resources) under the JSON license (additional to the license StackOverflow states to my posts). I was a student at a secondary technical college for IT until 2021. I like to experiment with things like WSL and I'm here to help others and get help. Programming languages that I like: java, java and (most importantly) JAVA (this list may or may not be comprehensive) GitHub Discord Tag: dan1st#7327 Other Accounts: dan2nd

Updated on September 18, 2022

Comments

  • dan1st
    dan1st over 1 year

    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.

    • Akina
      Akina over 4 years
      Add according right to this user via gpedit.msc. User\Templates\Network\Network Connections\Ability to Enable/Disable a LAN connection
    • dan1st
      dan1st over 4 years
      This program has not been found. Do I need Windows 10 pro/enterprise for this?
    • Akina
      Akina over 4 years
      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.
    • dan1st
      dan1st over 4 years
      The key is not available and I don't have the permission to create it, even not in HKCU.
    • Ramhound
      Ramhound over 4 years
      @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
    • dan1st
      dan1st over 4 years
      I correct myself: I hava no problem with needing administator privileges initially, but I don't want the UAC prompt every time.
    • dan1st
      dan1st over 4 years
      @Akina I found a way to activate the policy Ability to Enable/Disable a LAN connection. How can I enable/disable WLAN automatically with this?
    • Akina
      Akina over 4 years
      No, you cannot achieve this. Imagine it is disabled - how it can detect that it may self-enable?
    • somebadhat
      somebadhat over 4 years
      ToggleNIC 2 requires admin priv.
  • dan1st
    dan1st over 4 years
    It asks me for admin privileges automatically @somebadhat
  • somebadhat
    somebadhat over 4 years
    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.