# Script di disinstallazione del servizio Windows per Data Coupler # Eseguire come Amministratore param( [string]$ServiceName = "DataCouplerService" ) Write-Host "Disinstallazione Data Coupler Windows Service..." -ForegroundColor Yellow try { # Verifica se il servizio esiste $service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue if ($service) { Write-Host "Fermando il servizio $ServiceName..." -ForegroundColor Yellow Stop-Service -Name $ServiceName -Force -ErrorAction SilentlyContinue # Attende che il servizio si fermi completamente $timeout = 30 $counter = 0 while ((Get-Service -Name $ServiceName).Status -eq 'Running' -and $counter -lt $timeout) { Start-Sleep -Seconds 1 $counter++ Write-Host "." -NoNewline } Write-Host "" if ((Get-Service -Name $ServiceName).Status -eq 'Running') { Write-Warning "Il servizio non si è fermato entro $timeout secondi. Forzo la terminazione..." # Qui potresti aggiungere logica per terminare forzatamente il processo } Write-Host "Rimuovendo il servizio $ServiceName..." -ForegroundColor Yellow sc.exe delete $ServiceName # Verifica che il servizio sia stato rimosso Start-Sleep -Seconds 2 $removedService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue if (-not $removedService) { Write-Host "Servizio rimosso con successo!" -ForegroundColor Green } else { Write-Warning "Il servizio potrebbe non essere stato completamente rimosso. Prova a riavviare il sistema." } } else { Write-Host "Il servizio $ServiceName non è installato." -ForegroundColor Yellow } Write-Host "`nNOTA: I dati del database e le configurazioni sono conservati in C:\ProgramData\Data_Coupler" -ForegroundColor Cyan $response = Read-Host "Vuoi rimuovere anche i dati dell'applicazione? (y/N)" if ($response -eq 'y' -or $response -eq 'Y') { $dataPath = "C:\ProgramData\Data_Coupler" if (Test-Path $dataPath) { Write-Host "Rimuovendo i dati dell'applicazione..." -ForegroundColor Yellow Remove-Item -Path $dataPath -Recurse -Force Write-Host "Dati dell'applicazione rimossi." -ForegroundColor Green } } else { Write-Host "I dati dell'applicazione sono stati mantenuti in C:\ProgramData\Data_Coupler" -ForegroundColor Cyan } } catch { Write-Error "Errore durante la disinstallazione del servizio: $($_.Exception.Message)" exit 1 } Write-Host "`nDisinstallazione completata." -ForegroundColor Green