How to automatically log in to OpenVPN on Windows
Many people want to have their OpenVPN connection automatically start up and log in when they boot up their computer. Although there is no direct option in OpenVPN for Windows to accomplish it, it can be done.
The first step is to launch OpenVPN with a configuration attached so that it can connect to a server.
The following launch string is needed for either method:
For 32 bit Windows - C:\Program Files\OpenVPN\bin\openvpn-gui-1.0.3.exe --connect xxxxx.ovpn
For 64 bit Windows - C:\Program Files (x86)\OpenVPN\bin\openvpn-gui-1.0.3.exe --connect xxxxx.ovpn
The xxxxx is replaced with the name of the OpenVPN configuration file you wish to start. Your list of available .ovpn files can be found in the 'OpenVPN/config' folder on your computer.
The cleanest way to run this at boot up is to add it to the registry in the 'Run' section. Open regedit on your computer and go to:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
Add a new entry. Give it a name you can identify later such as "openvpn" then add the above string.
Note 1: If your Windows is not on the C: drive or you have OpenVPN installed in a different location, you will need to adjust the location in the above string to match your setup. You can also use the relative location such as %ProgramFiles% instead of C:\Program Files. However, that only solves the problem of Windows on a different drive. If you have OpenVPN loaded in a non standard location, you would still need to edit the string.
Note 2: For Windows Vista and Windows 7, OpenVPN-GUI must be run as administrator in order for the VPN to properly function. The most direct way to avoid these conflicts is to disable the UAC in Windows 7 and Vista. You can also set the program to always run as administrator in the properties of the application. Right-click on ' openvpn-gui-1.0.3.exe ', select 'Properties' then 'Compatibility'. Check the 'Run as Administrator' box.
Another way to do this would be to create a batch file containing the launch string above and place a shortcut for the file in the Windows startup folder. This method has the advantage of not having to touch the registry and taking the risk of inadvertently breaking something .
To do this, open notepad and enter one of the strings above. Save the file as 'openvpn.bat' in a folder, not on your desktop. Be sure to remove the 'default.txt' that notepad will try to save it as so that you don't end up with 'openvpn.bat.txt'. Right-click on the file, select 'Properties' then 'Compatibility'. Check the 'Run as Administrator' box. This is not necessary if you have the UAC off .
Go to the Windows startup folder and create a shortcut for the file.
When Windows boots with either method, it will start OpenVPN and attempt to log in to the VPN server that config file is pointing to.
OpenVPN will likely ask for a user name and password -- this is where things become problematic in Windows. Currently, there is no secure way to store the user name and password in Windows using OpenVPN. For security purposes, most versions of OpenVPN do not allow a user/password to be read from a file. If one is willing to take the security risk of having their login information saved in the clear on their hard drive, they can make OpenVPN automatically log in.
Recognizing the security risks the procedure is as follows:
1 - Create a file in the OpenVPN/config folder named password.txt
On the first line type your user name.
On the second line type your password
Save the file.
2 - Edit the .ovpn file referenced above in your launch string and find the line that reads 'auth-user-pass'.
Change it to 'auth-user-pass password.txt'.
3 - Install a custom version of OpenVPN that has the security turned off and that will read the user name and password from the file above. There are several sources on the internet of people offering such releases of OpenVPN. One such release of OpenVPN 2.11 can be downloaded here.
(Note: this link is provided as a reference only. We have tested the software and it works. But we do not control the content of this link and cannot guarantee the code that is there when you download it.)