first commit
This commit is contained in:
170
wireguard_service_installer.cmd
Normal file
170
wireguard_service_installer.cmd
Normal file
@@ -0,0 +1,170 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: UAC-Elevation prüfen und anfordern
|
||||
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
|
||||
if '%errorlevel%' NEQ '0' (
|
||||
echo Administratorrechte erforderlich. Starte Script als Administrator...
|
||||
goto UACPrompt
|
||||
) else (
|
||||
goto gotAdmin
|
||||
)
|
||||
|
||||
:UACPrompt
|
||||
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
|
||||
echo UAC.ShellExecute "%~s0", "%*", "", "runas", 1 >> "%temp%\getadmin.vbs"
|
||||
"%temp%\getadmin.vbs"
|
||||
del "%temp%\getadmin.vbs"
|
||||
exit /B
|
||||
|
||||
:gotAdmin
|
||||
pushd "%CD%"
|
||||
CD /D "%~dp0"
|
||||
|
||||
:: Parameter prüfen
|
||||
if "%~1"=="" (
|
||||
echo Fehler: Keine WireGuard-Konfigurationsdatei angegeben.
|
||||
echo Verwendung: %0 ^<pfad_zur_wireguard_config^>
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
set "CONFIG_FILE=%~1"
|
||||
|
||||
:: Prüfen ob Konfigurationsdatei existiert
|
||||
if not exist "%CONFIG_FILE%" (
|
||||
echo Fehler: Konfigurationsdatei "%CONFIG_FILE%" nicht gefunden.
|
||||
echo es wird ein WireGuard-Configfile als Parameter erwartet
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo WireGuard Installation und Konfiguration wird gestartet...
|
||||
|
||||
:: WireGuard Installation prüfen und ggf. installieren
|
||||
winget >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo Fehler: winget lässt sich nicht ausführen
|
||||
pause >nul
|
||||
exit /b 1
|
||||
)
|
||||
echo "Es wird ein Wireguard Service eingerichtet. <strg>+<c> zum beenden, <enter> weiter"
|
||||
pause >nul
|
||||
|
||||
echo Prüfe WireGuard Installation...
|
||||
winget install --id WireGuard.WireGuard --silent --accept-package-agreements --accept-source-agreements
|
||||
|
||||
echo Installiere Microsoft Visual C++ Redistributable...
|
||||
winget install --id Microsoft.VCRedist.2015+.x64 --accept-package-agreements --accept-source-agreements
|
||||
|
||||
:: Config-Verzeichnis erstellen
|
||||
set "CONFIG_DIR=%PROGRAMFILES%\WireGuard\config"
|
||||
echo Erstelle Konfigurationsverzeichnis: %CONFIG_DIR%
|
||||
|
||||
if not exist "%CONFIG_DIR%" (
|
||||
mkdir "%CONFIG_DIR%"
|
||||
if errorlevel 1 (
|
||||
echo Fehler: Konnte Konfigurationsverzeichnis nicht erstellen.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
|
||||
:: Berechtigungen setzen - Vererbung entfernen und nur Admin/LocalSystem
|
||||
echo Setze Berechtigungen für Konfigurationsverzeichnis...
|
||||
icacls "%CONFIG_DIR%" /inheritance:d >nul 2>&1
|
||||
icacls "%CONFIG_DIR%" /grant:r "Administratoren:(OI)(CI)F" >nul 2>&1
|
||||
icacls "%CONFIG_DIR%" /grant:r "SYSTEM:(OI)(CI)F" >nul 2>&1
|
||||
icacls "%CONFIG_DIR%" /remove "Benutzer" >nul 2>&1
|
||||
icacls "%CONFIG_DIR%" /remove "Authentifizierte Benutzer" >nul 2>&1
|
||||
|
||||
:: Konfigurationsdatei kopieren
|
||||
set "WG_CONFIG=%CONFIG_DIR%\wg0.conf"
|
||||
echo Kopiere Konfigurationsdatei nach %WG_CONFIG%...
|
||||
copy "%CONFIG_FILE%" "%WG_CONFIG%" >nul
|
||||
if errorlevel 1 (
|
||||
echo Fehler: Konnte Konfigurationsdatei nicht kopieren.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: WireGuard Tunnel Service installieren
|
||||
echo Installiere WireGuard Tunnel Service...
|
||||
"%PROGRAMFILES%\WireGuard\wireguard.exe" /installtunnelservice "%WG_CONFIG%"
|
||||
|
||||
:: Service-Berechtigungen setzen
|
||||
echo Setze Service-Berechtigungen...
|
||||
sc sdset "WireGuardTunnel$wg0" "D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;RPWPDTRCWD;;;AU)(A;;CCLCSWLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)" >nul 2>&1
|
||||
|
||||
:: Zusätzliche Dateien kopieren
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
set "WG_DIR=%PROGRAMFILES%\WireGuard"
|
||||
|
||||
echo Kopiere zusätzliche Dateien...
|
||||
|
||||
:: WireGuardMon.exe kopieren
|
||||
copy "%SCRIPT_DIR%wireguardmon.exe" "%WG_DIR%\" >nul
|
||||
if errorlevel 1 (
|
||||
echo Warnung: Konnte wireguardmon.exe nicht kopieren.
|
||||
pause
|
||||
) else (
|
||||
echo wireguardmon.exe erfolgreich kopiert.
|
||||
)
|
||||
|
||||
:: VPNTray.exe kopieren
|
||||
copy "%SCRIPT_DIR%VPNTray.exe" "%WG_DIR%\" >nul
|
||||
if errorlevel 1 (
|
||||
echo Warnung: Konnte VPNTray.exe nicht kopieren.
|
||||
pause
|
||||
) else (
|
||||
echo VPNTray.exe erfolgreich kopiert.
|
||||
)
|
||||
|
||||
:: VPNTray.ini kopieren
|
||||
copy "%SCRIPT_DIR%VPNTray.ini" "%WG_DIR%\" >nul
|
||||
if errorlevel 1 (
|
||||
echo Warnung: Konnte VPNTray.ini nicht kopieren.
|
||||
pause
|
||||
) else (
|
||||
echo VPNTray.ini erfolgreich kopiert.
|
||||
)
|
||||
|
||||
:: WireGuardMon installieren
|
||||
if exist "%WG_DIR%\wireguardmon.exe" (
|
||||
echo Installiere WireGuardMon...
|
||||
pushd "%WG_DIR%"
|
||||
wireguardmon.exe --install
|
||||
if errorlevel 1 (
|
||||
echo Warnung: WireGuardMon Installation fehlgeschlagen.
|
||||
pause
|
||||
) else (
|
||||
echo WireGuardMon erfolgreich installiert.
|
||||
net start wireguardmon
|
||||
)
|
||||
popd
|
||||
) else (
|
||||
echo Warnung: WireGuardMon nicht verfügbar - Installation übersprungen.
|
||||
pause >nul
|
||||
)
|
||||
|
||||
:: Autostart-Eintrag für VPNTray.exe erstellen
|
||||
if exist "%WG_DIR%\VPNTray.exe" (
|
||||
echo Erstelle Autostart-Eintrag für VPNTray...
|
||||
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "VPNTray" /t REG_SZ /d "\"%WG_DIR%\VPNTray.exe\"" /f >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo Warnung: Autostart-Eintrag konnte nicht erstellt werden.
|
||||
pause
|
||||
) else (
|
||||
echo Autostart-Eintrag für VPNTray erfolgreich erstellt.
|
||||
)
|
||||
start "" explorer.exe "%WG_DIR%\VPNTray.exe"
|
||||
) else (
|
||||
echo Warnung: VPNTray.exe nicht verfügbar - Autostart-Eintrag übersprungen.
|
||||
)
|
||||
|
||||
echo.
|
||||
echo Drücke eine beliebige Taste zum Beenden...
|
||||
pause >nul
|
||||
|
||||
endlocal
|
||||
Reference in New Issue
Block a user