How can I automate in Windows 11 to click on Auto Connect or Connect for a specific VPN under Windows Settings VPN?

Hello,

I have Windows 11 and a VPN configured under Windows Settings VPN.

Currently, when I want to auto-connect (or connect) to the VPN, I have to go through following 3 steps that are in the screenshots:

https://imgur.com/a/qjVZywh

Step 1: Click in the tray on the “internet/sound/battery” icons block.

Step 2: This will open a small window of the settings (similar to control center in iPhone/Android) - Click there on VPN button

Step 3: This will show the list of VPNs configured, expand/click on the VPN you want to connect and then either click “Connect automatically” or “Connect”.

How can I automate this in Powershell or alternative ways?

I’m looking for a simple one liner command to simulate the “automatically connect” or “connect” for a specific vpn that shows under the windows settings vpn when you expand a specific vpn line.

Just for reference, to disconnect from a VPN, it’s a simple one line command:

rasdial $vpnName /DISCONNECT;

And I already confirmed this works for the same vpn I was able to manually “automatically connect” or “connect”. Now, I’m looking for the equivalent command just for doing an auto-connect or connect to the vpn. I didn’t see under rasdial command options that it has anything to do with “/CONNECT” just “/DISCONNECT” and some other options.

TDLR: I’m looking for a XXXX command such as:

XXXXX $vpnName /AUTOCONNECT

or

XXXX $vpnName /CONNECT

Alternatively (if that’s easier), can I use powershell to open the specific settings window to open the second screenshot window (how do I do that?) and then simulate a mouse click in that area on the vpn and another one on the auto connect?

Thank you.

For more designs, concepts and ideas related to Windows, check out r/Windows_Redesign!


This submission has NOT been removed. Concept posts are always allowed here as per our community rules.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

I have found the power automate tool in windows really good. It comes with a clicking feature if something isn’t directly reachable.

VPN auto-triggered profile options

Alternatively, check out Rasdial

rasdial vpnname username password

(use * instead of password to get a prompt.)

Or rasphone -d "vpnname"

How do you use that to click on something? Got some detailed instructions or commands examples to run in powershell?

Well this VPN that I want to click auto connect is based on another app from Microsoft called Azure VPN Client. So I’m not sure if it’s still using the traditional way like the other VPNs, but I did find this:

I found this article that says “Set your Azure VPN connections to “Connect Automatically” with PowerShell”

https://powers-hell.com/2020/11/28/set-your-azure-vpn-connections-to-connect-automatically-with-powershell/

But I’m a little lost on how the “Retry reconnect” is being accomplished using powershell and/or Intune? Can you just do with Powershell or Task scheduler or command line to tell it to reconnect if it lost connection?

Someone also commented on the app review section and got a response from Microsoft:

Works well - just needs some extra features
Seems to work well, especially after the last update. To deploy this as an Enterprise solution it needs a few extra features. I'm looking to be able to configure/manage it via
Intune/Config Mgr or PowerShell etc. I like that I can now import the profile from the command line and that I can add routes and DNS suffixes to the profile XML file. What I'm still looking
for is the ability to configure automatic connection programmatically and Network Location Awareness so it doesn't try to connect when a device is connected to the cooperate network.
Pete 3 years ago
=======Response from Microsoft Corporation======
Thank you for your feedback, we are glad that you like the product. You can deploy a store app using Intune and then import the profile using a command-line script. https://docs.microsoft.com/en-us/azure/vpn-gateway/openvpn-azure-ad-client#can-i-imprt-the-profile-from-a-command-line-prompt%20. . We are evaluating the Network Location Awareness
request. Please check https://azure.microsoft.com/en-us/blog/topics/announcements/ for any updates

The author from the article above also mentioned: "

The key to this solution is found in the registry (as always). The auto connection settings can be found in the local machine hive path shown below.

HKLM:\SYSTEM\CurrentControlSet\Services\RasMan\Config"

But when I go there, I don’t see the setting AutoTriggerDisabledProfileList or any other from his screenshots, so it’s not clear if I’m supposed to add them manually or they’re supposed to appear there?

I also found this article about this registry setting:

https://msendpointmgr.com/2020/04/29/keeping-always-on-vpn-always-on/

But this has something to do with another program called Always On VPN?

Would appreciate if you have any suggestions or advice.

Just for reference, to disconnect from a VPN, it’s a simple one line command:

rasdial $vpnName /DISCONNECT;

And I already confirmed this works for the same vpn I was able to manually “automatically connect” or “connect”. Now, I’m looking for the equivalent command just for doing an auto-connect or connect to the vpn. I didn’t see under rasdial command options that it has anything to do with “/CONNECT” just “/DISCONNECT” and some other options.

TDLR: I’m looking for a XXXX command such as:

XXXXX $vpnName /AUTOCONNECT

or

XXXX $vpnName /CONNECT

Alternatively (if that’s easier), can I use powershell to open the specific settings window to open the second screenshot window (how do I do that?) and then simulate a mouse click in that area on the vpn and another one on the auto connect?

I think I saw here sometime someone mentioned there is a command that could open any navigation windows 11 settings page by using some sort of url like settings/vpn/etc how do I find what’s the settings url for the second screenshot so I could run a command to launch it with powershell?

Thank you.

Will it use the auto connect or just the regular connect? Is that the username and password of my logged in user?

I just tried it. It doesn’t work:

PS C:\ps> rasdial “XXXX”

Remote Access error 623 - The system could not find the phone book entry for this connection.

For more help on this error:

Type "hh netcfg.chm’

In help, click Troubleshooting, then| Error Messages, then 623

Note that this VPN connection is created through Azure VPN Client app from Microsoft but it also showing under the Windows 11 Settings VPN section (So I’m not sure if it’s still using the traditional way like the other VPNs and if it will be in the regular phone book entries that rasdial typically dials).

See more details that I wrote about it here:

https://www.reddit.com/r/PowerShell/comments/13tv4k6/how\_can\_i\_automate\_in\_windows\_11\_to\_click\_on\_auto/jlxazxb/

You can create a new flow, then go to mouse and keyboard in the actions tab and select wherever you want to click via x and y coordinates. The actual clicking is separate though so in your flow you would do the mouse movement and afterwards add a click action.

Additionally you can add running any script. Personally I have not exhausted the possibilities the actions tab gives you so you might want to tinker with it yourself and see if it does what you need it to.

Read the documentation I linked. RasDial will connect if you provide the username/password needed for the connection. So,basically rasdial $vpnName $userName $password

Do you have some screenshot example of your flow of how you do the clicking? Thanks.

This is a basic example of how you could start mullvad, then move the mouse to the position where mullvad opens on the screen, click connect and you are done. The whole thing is really fast, you can set certain routines and launch flows from the taskbar if the app is minimized. This took two minutes to set up, most of the time was me searching for the exe.

Of course I would not do this because the mullvad app comes with an auto start and connect function, but this is an example after all.

I never used any of that so I don’t know. Just found your question interesting and did a bit of googling.

As the linked documentation suggests, it’s the account/password for the VPN, so if it’s the same account as the one you’re logged in with, it’s going to be the same.

Thanks, so let’s say I create a macro with the 3 mouse clicks from my screenshot. How do I create a shortcut to my macro so I can just double click on it and it will execute?

https://learn.microsoft.com/en-us/power-automate/getting-started

Any other alternative apps to simulate mouse clicks? Can I simulate a mouse click with a batch or powershell script? Or AutoHotKey perhaps?

At this point just ask chat gpt to write you a script. Honesty, I feel like I am being prompted right now.

It just Power Automate feels too heavy for something relatively simple so I was looking for alternatives… But asking chatgpt might be a good idea…