Skip to content

Instantly share code, notes, and snippets.

@NBprojekt
Last active January 13, 2021 11:05
Show Gist options
  • Save NBprojekt/8609ed86c0f55c3269a044b8b422fc68 to your computer and use it in GitHub Desktop.
Save NBprojekt/8609ed86c0f55c3269a044b8b422fc68 to your computer and use it in GitHub Desktop.
Open-VPN Start Before Logon Service

Open-VPN SBL

Create Open-VPN Connection on Boot to apply Group Policy and ensure the user can log in using Active Directory

  1. Download (nssm)(https://nssm.cc/download) and place it next to the Powershell script
  2. Run the Powershell script using an elevated command line
  3. (Optional) Delete script and exe
  4. Reboot
#Requires -RunAsAdministrator
$nssmPath = ".\nssm.exe"
$nssmExists = Test-Path $nssmPath
if (-Not $nssmExists) {
echo "Make sure nssm.exe is in $nssmPath"
}
Start-Process -NoNewWindow -FilePath nssmPath -ArgumentList "install OpenVPN-SBL `"C:\Program Files\OpenVPN\bin\openvpn.exe`""
Start-Process -NoNewWindow -FilePath nssmPath -ArgumentList "set OpenVPN-SBL Start SERVICE_AUTO_START"
Start-Process -NoNewWindow -FilePath nssmPath -ArgumentList "set OpenVPN-SBL DisplayName VPN SBL"
Start-Process -NoNewWindow -FilePath nssmPath -ArgumentList "set OpenVPN-SBL Description Creates VPN Connection before logon"
Start-Process -NoNewWindow -FilePath nssmPath -ArgumentList "set OpenVPN-SBL ObjectName LocalSystem"
Start-Process -NoNewWindow -FilePath nssmPath -ArgumentList "set OpenVPN-SBL Type SERVICE_WIN32_OWN_PROCESS"
Start-Process -NoNewWindow -FilePath nssmPath -ArgumentList "set OpenVPN-SBL DependOnService Dhcp tap0901"
Start-Process -NoNewWindow -FilePath nssmPath -ArgumentList "set OpenVPN-SBL AppDirectory `"C:\Program Files\OpenVPN\config`""
Start-Process -NoNewWindow -FilePath nssmPath -ArgumentList "set OpenVPN-SBL AppParameters --config SBL.ovpn"
Start-Process -NoNewWindow -FilePath nssmPath -ArgumentList "set OpenVPN-SBL AppStdout `"C:\Program Files\OpenVPN\log\SBL.log`""
Start-Process -NoNewWindow -FilePath nssmPath -ArgumentList "set OpenVPN-SBL AppStderr `"C:\Program Files\OpenVPN\log\SBL.log`""
Start-Process -NoNewWindow -FilePath nssmPath -ArgumentList "set OpenVPN-SBL AppStdoutCreationDisposition 2"
Start-Process -NoNewWindow -FilePath nssmPath -ArgumentList "set OpenVPN-SBL AppStderrCreationDisposition 2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment