param ( [string]$Action ) # Default values for the service $ServicePath = ".\SoraV2Utils_Service.exe" $ServiceName = "SoraV2Utils_Service" $Description = "SoraV2 Utils Service" $DisplayName = "SoraV2 Utils Service" # Function to install the service function Install-Service { param ( [string]$ServicePath, [string]$ServiceName, [string]$Description, [string]$DisplayName ) $FullServicePath = (Resolve-Path -Path $ServicePath).Path New-Service -Name $ServiceName -BinaryPathName $FullServicePath -Description $Description -DisplayName $DisplayName -StartupType Automatic Write-Host "Service '$ServiceName' installed successfully." } # Function to remove the service function Remove-Service { param ( [string]$ServiceName ) Stop-Service -Name $ServiceName -Force sc.exe delete $ServiceName Write-Host "Service '$ServiceName' removed successfully." } # Function to start the service function Start-Service { param ( [string]$ServiceName ) Start-Service -Name $ServiceName Write-Host "Service '$ServiceName' started successfully." } # Function to stop the service function Stop-Service { param ( [string]$ServiceName ) Stop-Service -Name $ServiceName Write-Host "Service '$ServiceName' stopped successfully." } # Function to get the status of the service function Get-ServiceStatus { param ( [string]$ServiceName ) $Service = Get-Service -Name $ServiceName Write-Host "Service '$ServiceName' is $($Service.Status)." } # Main script logic switch ($Action.ToLower()) { "install" { Install-Service -ServicePath $ServicePath -ServiceName $ServiceName -Description $Description -DisplayName $DisplayName break } "remove" { Remove-Service -ServiceName $ServiceName break } "start" { Start-Service -ServiceName $ServiceName break } "stop" { Stop-Service -ServiceName $ServiceName break } "status" { Get-ServiceStatus -ServiceName $ServiceName break } default { Write-Host "Usage: .\Install-Service.ps1 -Action " break } }