Skip to content

Instantly share code, notes, and snippets.

@kralo
Created September 10, 2021 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kralo/863be16b9f087671dc12675cf0ed0f0a to your computer and use it in GitHub Desktop.
Save kralo/863be16b9f087671dc12675cf0ed0f0a to your computer and use it in GitHub Desktop.
wireguard client on windows unprivileged user restart tunnel

Howto install wireguard as tunnel-Service when user is not local administrator.

See the setup .bat for setup. Key here is to set the service rights, so that anyone can restart the service.

See the restart script for how to restart. this is especially useful if the tunnel is "broken", because the peer is behind a dynamic dns service.

REM replace <Tunnelname> as appropriate
sc stop "WireguardTunnel$<Tunnelname>"
timeout /t 10
sc start "WireguardTunnel$<Tunnelname>"
timeout /t 3
sc query "WireguardTunnel$<Tunnelname>"
pause
REM originally from https://administrator.de/contentid/603185#comment-1478311
@echo off
:: restart elevated if needed
net session >nul 2>&1 || (powershell -EP Bypass -NoP -C start "%~0" -verb runas &exit /b)
:: read config path from user
set /p tunnelconfig=Please enter path to wireguard *.conf file:
:: get tunnel name from config file name, filename without extension
for /f "delims=" %%a in ("%tunnelconfig%") do set "tunnelname=%%~na"
echo Creating tunnel service with name "WireguardTunnel$%tunnelname%"
"C:\Program Files\wireguard\wireguard.exe" /installtunnelservice "%tunnelconfig%"
echo Setting service permissions for local "Users" group to allow service start/stop
sc sdset "WireguardTunnel$%tunnelname%" "D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)(A;;CRRPRCWPDT;;;BU)"
echo Setting service start mode to manual
REM sc config "WireguardTunnel$%tunnelname%" start= delayed-auto
sc config "WireguardTunnel$%tunnelname%" start= demand
echo.
pause
REM "C:\Program Files\wireguard\wireguard.exe" /uninstalltunnelservice <TUNNELNAME>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment