banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

[Windows] Automatically connect to VPN or ADSL on startup

VPN connections or ADSL connections created on Windows servers cannot be automatically dialed and connected like on Linux using simple commands or startup scripts. However, there are many methods available in the Windows environment to achieve this functionality. The simplest method is usually to drag the dial-up connection to the startup directory or add it to the task scheduler. However, it becomes more complicated when setting it up on a server. Fortunately, Windows provides a tool called rasdial.exe to solve this problem.

To connect to a specific connection using rasdial.exe, the connection name is specified as a parameter. User passwords can also be set. The connection can be a VPN connection or a dial-up connection like PPOE.

#VPN
rasdial myvpn
#ADSL
rasdial myadsl
#VPN
rasdial myvpn username password
#ADSL
rasdial myadsl username password

To disconnect a specific connection:

#VPN
rasdial myvpn /disconnect
#ADSL
rasdial myadsl /disconnect

To configure it as a system service that starts automatically, you can also configure a system service, which provides a permanent solution. For this, you will need two tools: Instsrv.exe and Srvany.exe, which can be found in the Microsoft Windows Resource Kits. Download link: http://www.microsoft.com/en-us/download/details.aspx?id=17657

Usage:

#Create a service
Instsrv.exe AutoVPNDial Srvany.exe
#Set registry information
reg add Parameters /v HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\AutoVPNDial
reg add Application /v HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\AutoVPNDial\Parameters /v "%windir%\system32\rasdial.exe myvpn" /t REG_SZ

To remove the system service:

Instsrv AutoVPNDial remove

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.