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
Add according right to this user via gpedit.msc. User\Templates\Network\Network Connections\Ability to Enable/Disable a LAN connection – Akina – 2019-10-09T13:45:36.323
This program has not been found. Do I need Windows 10 pro/enterprise for this? – dan1st – 2019-10-09T13:46:39.807
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 – 2019-10-09T13:49:27.600
The key is not available and I don't have the permission to create it, even not in
HKCU
. – dan1st – 2019-10-09T13:57:48.280@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 – 2019-10-09T17:15:14.093
I correct myself: I hava no problem with needing administator privileges initially, but I don't want the UAC prompt every time. – dan1st – 2019-10-09T17:22:40.387
@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? – dan1st – 2019-10-16T14:51:30.717No, you cannot achieve this. Imagine it is disabled - how it can detect that it may self-enable? – Akina – 2019-10-16T14:57:14.827
ToggleNIC 2 requires admin priv. – somebadhat – 2019-10-25T01:49:17.077