add Paramter Switch for IP

This commit is contained in:
Tobias Poetzsch 2025-05-21 13:35:47 +02:00
parent 2bf8287cb5
commit 46d925d6bb
2 changed files with 98 additions and 58 deletions

View File

@ -1,3 +1,16 @@
@echo off
powershell.exe -NoProfile -ExecutionPolicy Bypass -File Set-ELP-Host.ps1
pause
setlocal
REM Set the path to the PowerShell script
set SCRIPT_PATH=Set-ELP-Host.ps1
REM Check if an IP was passed as a parameter to the batch file
if "%~1"=="" (
REM No parameter passed: run script in interactive mode
powershell.exe -ExecutionPolicy Bypass -File "%SCRIPT_PATH%"
) else (
REM Parameter passed: run script with DirektIP argument
powershell.exe -ExecutionPolicy Bypass -File "%SCRIPT_PATH%" -DirektIP "%~1"
)
endlocal

View File

@ -1,74 +1,101 @@
# Path INI-Datei
param(
[string]$DirektIP # Optional parameter to directly set the IP address
)
# Define paths
$iniPath = "C:\EDP\ELP\ELP.ini"
$exePath = "C:\EDP\ELP\ELP.exe"
Write-Host "`n"
# Print menue
Write-Host "Bitte EDP-Server bestimmen:`n"
Write-Host "1 = 192.168.112.10 (ELW RK TUT 50/11-1)"
Write-Host "2 = 172.20.2.101 (DRK Spaichingen)"
#Write-Host "3 = edp-schulung.drk-spa.de (DRK Schulung)"
Write-Host "9 = 127.0.0.1 (Lokaler Server)"
Write-Host ""
# Read userinput
$wahl = Read-Host "Ihre Auswahl (1 bis 9)"
# select IP from userinput
switch ($wahl)
# Function to update the Host= entry in the INI file
function SetHostIP($ip)
{
"1"
{
$neueIP = "192.168.112.10"
}
"2"
{
$neueIP = "172.20.2.101"
}
"3"
{
$neueIP = "edp-schulung.drk-spa.de"
}
"9"
{
$neueIP = "127.0.0.1"
}
Default
if (Test-Path $iniPath)
{
Write-Host "Unbekannte Auswahl. Vorgang abgebrochen." -ForegroundColor Red
exit
$iniContent = Get-Content $iniPath
$iniContent = $iniContent -replace '^Host=.*$', "Host=$ip"
Set-Content -Path $iniPath -Value $iniContent
Write-Host "Der EDP-Server wurde auf '$ip' gesetzt." -ForegroundColor Green
}
else
{
Write-Host "INI-Datei '$iniPath' wurde nicht gefunden." -ForegroundColor Red
exit 1
}
}
# read ini File
if (Test-Path $iniPath)
# Function to start the EDP application
function StartEDP()
{
$iniInhalt = Get-Content $iniPath
if (Test-Path $exePath)
{
Write-Host "Starte EDP Einsatzleitplatz..."
Start-Process $exePath
}
else
{
Write-Host "Die Anwendung '$exePath' wurde nicht gefunden." -ForegroundColor Red
}
}
# find line with "Hosts= and replace IP
$iniInhalt = $iniInhalt -replace '^Host=.*$', "Host=$neueIP"
# Write INI File
Set-Content -Path $iniPath -Value $iniInhalt
#Print promt
Write-Host "`nDer EDP-Server wurde auf '$neueIP' gewechselt." -ForegroundColor Green
}
else
# If a parameter is provided, directly set IP and start EDP
if ($DirektIP)
{
#Print Errer 404
Write-Host "Die Datei '$iniPath' wurde nicht gefunden." -ForegroundColor Red
SetHostIP -ip $DirektIP
StartEDP
exit
}
$wahl = Read-Host "Soll EDP Einsatzleitplatz gestartet werden? (Y/n)"
# Interactive menu if no parameter was passed
Write-Host "`nBitte EDP-Server bestimmen:`n"
Write-Host "1 = 192.168.112.10 (ELW RK TUT 50/11-1)"
Write-Host "2 = 172.20.2.101 (DRK Spaichingen)"
# Write-Host "3 = edp-schulung.drk-spa.de (DRK Schulung)"
Write-Host "9 = 127.0.0.1 (Lokaler Server)"
Write-Host ""
if ($wahl -in @("Y", "y", "1", ""))
# Get user input
$selection = Read-Host "Ihre Auswahl (1 bis 9)"
# Map selection to IP address
switch ($selection)
{
Write-Host "Starte EDP Einsatzleitplatz..."
Start-Process "C:\EDP\ELP\ELP.exe"
"1"
{
$newIP = "192.168.112.10"
}
"2"
{
$newIP = "172.20.2.101"
}
"3"
{
$newIP = "edp-schulung.drk-spa.de"
}
"9"
{
$newIP = "127.0.0.1"
}
Default
{
Write-Host "Ungültige Auswahl. Vorgang abgebrochen." -ForegroundColor Red
exit 1
}
}
# Apply change
SetHostIP -ip $newIP
# Ask whether to start the EDP app
$startChoice = Read-Host "Soll EDP Einsatzleitplatz gestartet werden? (Y/n)"
if ($startChoice -in @("Y", "y", "1", ""))
{
StartEDP
}
else
{
Write-Host "EDP wird nicht gestartet"
}
Write-Host "EDP wird nicht gestartet."
}