#requires -version 5.1 param( [switch]$SkipPassword, [switch]$SkipPsCheck ) Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing $script:WizardRoot = if ($PSScriptRoot) { $PSScriptRoot } else { (Get-Location).Path } $script:WizardInstallPath = if ($PSCommandPath) { $PSCommandPath } else { Join-Path $script:WizardRoot 'install.ps1' } if ($script:WizardRoot -and (Test-Path -LiteralPath $script:WizardRoot)) { Set-Location -LiteralPath $script:WizardRoot } # Crea la directory "scripts" se non esiste if (-not (Test-Path -Path "./scripts")) { Write-Host "Creazione della directory 'scripts'..." -ForegroundColor Yellow New-Item -ItemType Directory -Path "./scripts" | Out-Null Write-Host "Directory 'scripts' creata con successo." -ForegroundColor Green } $files = @( "install.ps1", "WizardUI.ps1", "assets/wizard.ico", "PowerShellUtils.ps1", "FileUtils.ps1", "scripts/Action-InstallSiacloud.ps1", "scripts/Action-InstallNuvoletta.ps1", "scripts/Action-InstallOpenVPN.ps1", "scripts/Action-As400.ps1", "scripts/Action-InstallBarTender.ps1", "scripts/Action-PcClean.ps1", "scripts/Action-RemoveMcAfee.ps1", "scripts/Action-Pouch.ps1", "scripts/Action-AvviaBios.ps1", "scripts/Action-AvviaHBCDRamdisk.ps1", "scripts/Action-AvviaRescuezillaRamUEFI.ps1", "scripts/Action-BlockUpdate2.ps1", "scripts/Action-RunChrisTitusScript.ps1", "scripts/Action-WinTool.ps1", "scripts/Action-Office.ps1", "scripts/Action-ResetIDAnyDeskV4.ps1", "scripts/Action-DiskCleanV1.ps1", "scripts/Action-ScanSistema.ps1", "scripts/Action-NewPc.ps1" ) $baseUrl = "https://wizard.advancdev.com" if (-not (Test-Path -Path "./assets")) { New-Item -ItemType Directory -Path "./assets" -Force | Out-Null } foreach ($file in $files) { $parentDir = Split-Path -Path "./$file" -Parent if ($parentDir -and -not (Test-Path -Path $parentDir)) { New-Item -ItemType Directory -Path $parentDir -Force | Out-Null } if (-not (Test-Path -Path "./$file")) { Write-Host "Download $file..." -ForegroundColor Yellow Invoke-WebRequest -Uri "$baseUrl/$file" -OutFile "./$file" -UseBasicParsing Write-Host "$file scaricato." -ForegroundColor Green } else { Write-Host "Aggiornamento $file..." -ForegroundColor Yellow Invoke-WebRequest -Uri "$baseUrl/$file" -OutFile "./$file" -UseBasicParsing Write-Host "$file aggiornato." -ForegroundColor Green } } $localInstall = Join-Path $script:WizardRoot 'install.ps1' if (Test-Path -LiteralPath $localInstall) { $script:WizardInstallPath = (Resolve-Path -LiteralPath $localInstall).Path } # Se avviato via iex (irm), riesegui install.ps1 aggiornato da disco if (-not $script:WizardRelaunched -and $script:WizardInstallPath -and (Test-Path -LiteralPath $script:WizardInstallPath)) { $runningFromDisk = $false if ($PSCommandPath) { try { $runningFromDisk = ((Resolve-Path -LiteralPath $PSCommandPath).Path -eq $script:WizardInstallPath) } catch { } } if (-not $runningFromDisk) { $script:WizardRelaunched = $true $relaunchArgs = @() if ($SkipPassword) { $relaunchArgs += '-SkipPassword' } if ($SkipPsCheck) { $relaunchArgs += '-SkipPsCheck' } & $script:WizardInstallPath @relaunchArgs exit } } # ===================== # Importa file di utilità e azioni # ===================== . ./PowerShellUtils.ps1 . ./FileUtils.ps1 . ./WizardUI.ps1 Set-WizardBaseUrl -Url $baseUrl . ./scripts/Action-InstallSiacloud.ps1 . ./scripts/Action-InstallNuvoletta.ps1 . ./scripts/Action-InstallOpenVPN.ps1 . ./scripts/Action-As400.ps1 . ./scripts/Action-InstallBarTender.ps1 . ./scripts/Action-PcClean.ps1 . ./scripts/Action-RemoveMcAfee.ps1 . ./scripts/Action-Pouch.ps1 . ./scripts/Action-AvviaBios.ps1 . ./scripts/Action-AvviaHBCDRamdisk.ps1 . ./scripts/Action-AvviaRescuezillaRamUEFI.ps1 . ./scripts/Action-BlockUpdate2.ps1 . ./scripts/Action-RunChrisTitusScript.ps1 . ./scripts/Action-WinTool.ps1 . ./scripts/Action-Office.ps1 . ./scripts/Action-ResetIDAnyDeskV4.ps1 . ./scripts/Action-DiskCleanV1.ps1 . ./scripts/Action-ScanSistema.ps1 . ./scripts/Action-NewPc.ps1 # ===================== # BLOCCO PASSWORD # ===================== $PasswordCorreta = "Serazi123!" # <-- Cambia qui la password desiderata $MaxTentativiPassword = 3 $script:PasswordAccettata = $SkipPassword $script:TentativiPasswordRimasti = $MaxTentativiPassword if (-not $SkipPassword) { while (-not $script:PasswordAccettata -and $script:TentativiPasswordRimasti -gt 0) { $entered = Show-WizardPasswordDialog -Subtitle "Tentativi rimasti: $script:TentativiPasswordRimasti" if ($null -eq $entered) { break } if ($entered -ne $PasswordCorreta) { $script:TentativiPasswordRimasti-- if ($script:TentativiPasswordRimasti -le 0) { [System.Windows.Forms.MessageBox]::Show("Password errata. Tentativi esauriti. Lo script verrà chiuso.","Errore",'OK','Error') | Out-Null Stop-Process -Id $PID } else { [System.Windows.Forms.MessageBox]::Show("Password errata. Tentativi rimasti: $script:TentativiPasswordRimasti","Errore",'OK','Error') | Out-Null } } else { $script:PasswordAccettata = $true } } } if (-not $script:PasswordAccettata) { Stop-Process -Id $PID } $ErrorActionPreference = 'Stop' # ===================== # CONTROLLO VERSIONE POWERSHELL # ===================== # Script per aggiornare PowerShell 7 - Versione migliorata # Risolve problemi di connessione e compatibilità # Carica Windows Forms solo se necessario Add-Type -AssemblyName System.Windows.Forms # Verifica privilegi amministrativi function Test-AdminRights { $currentUser = [Security.Principal.WindowsIdentity]::GetCurrent() $principal = New-Object Security.Principal.WindowsPrincipal($currentUser) return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) } # Main execution Write-Host "=== Script Aggiornamento PowerShell 7 ===" -ForegroundColor Magenta Write-Host "Versione migliorata con gestione errori avanzata" -ForegroundColor Gray Write-Host "" # Controllo privilegi amministrativi if (-not (Test-AdminRights)) { Write-Host "ATTENZIONE: Esecuzione senza privilegi amministrativi." -ForegroundColor Yellow Write-Host "L'installazione potrebbe richiedere l'elevazione dei privilegi." -ForegroundColor Yellow Write-Host "" } if (-not $SkipPsCheck) { Check-PowerShellVersion -InstallScriptPath $script:WizardInstallPath -WorkingDirectory $script:WizardRoot } Write-Host "" Write-Host "Aggiornamento completato. 🚀 Premi un tasto per avviare il wizard..." -ForegroundColor Gray if (-not $SkipPsCheck) { $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null } # ===================== # CONFIG: imposta il tuo BASE URL # ===================== $BASE = $env:WIZARD_BASEURL if ([string]::IsNullOrWhiteSpace($BASE)) { $BASE = "https://wizard.advancdev.com" } function Get-Json($url) { Invoke-RestMethod -Uri $url -UseBasicParsing } function Join-Url($a, $b) { if ($a.TrimEnd('/') -eq '') { return $b } return ($a.TrimEnd('/') + '/' + $b.TrimStart('/')) } $manifestUrl = Join-Url $BASE "manifest.json" $manifest = Get-Json $manifestUrl $Title = if ($manifest.title) { $manifest.title } else { "Siacloud Wizard" } # ===================== # HELPERS # ===================== function Show-Info($msg) { [System.Windows.Forms.MessageBox]::Show($msg, $Title, 'OK', 'Information') | Out-Null } function Show-YesNo($msg) { [System.Windows.Forms.MessageBox]::Show($msg, $Title, 'YesNo', 'Question') } function Run-Process($file, $args = "", [switch]$Wait) { Write-Host "Running $file $args" $p = Start-Process -FilePath $file -ArgumentList $args -PassThru if ($Wait) { $p.WaitForExit() } } # ===================== # GUI UTILITY # ===================== function Action-Utilities { $utilShell = New-WizardForm -Title "$Title - Utilità" -Subtitle "Strumenti di manutenzione e configurazione" -Width 480 -Height 420 $utilForm = $utilShell.Form $utilMenu = New-WizardListBox @( 'Inizializza nuovo PC ed installa app*', 'Blocca aggiornamenti driver stampanti*', 'Pulizia PC', 'Entra nel BIOS', 'Avvia Hiren''s BootCD PE*', 'Avvia Rescuezilla in RAM (UEFI)*', 'Rimuovi McAfee', 'Debloating', 'WinTools', 'Office Tool', 'Reset AnyDesk ID*', 'Pulizia Disco Profonda*', 'Scansione del sistema*', 'Backup Pouch' ) | ForEach-Object { [void]$utilMenu.Items.Add($_) } $utilBtn = New-WizardPrimaryButton -Text "Esegui" $backBtn = New-WizardSecondaryButton -Text "Indietro" Add-WizardFooterButtons -FooterPanel $utilShell.FooterPanel -Buttons @($backBtn, $utilBtn) $utilBtn.Add_Click({ switch ($utilMenu.SelectedIndex) { 0 { Action-NewPc } 1 { Action-BlockUpdate2 } 2 { Action-PcClean } 3 { Action-AvviaBios } 4 { Action-AvviaHBCDRamdisk } 5 { Action-AvviaRescuezillaRamUEFI } 6 { Action-RemoveMcAfee } 7 { Action-RunChrisTitusScript } 8 { Action-WinTool } 9 { Action-Office } 10 { Action-ResetAnyDesk } 11 { Action-DiskClean } 12 { Action-ScanSystem } 13 { Action-Pouch } default { Show-Info "Seleziona un'utilità." } } }) $backBtn.Add_Click({ $utilForm.Close() }) Add-WizardContentFullList -ContentPanel $utilShell.ContentPanel -ListControl $utilMenu [void]$utilForm.ShowDialog() } # ===================== # GUI PRINCIPALE # ===================== $versionFooter = if ($manifest.siacloud.version) { "Siacloud v$($manifest.siacloud.version)" } else { '' } $mainShell = New-WizardForm -Title $Title -Subtitle "Seleziona un'operazione da eseguire" -Width 480 -Height 420 -FooterText $versionFooter $form = $mainShell.Form $menu = New-WizardListBox @( 'Scarica e installa Siacloud', 'Scarica Nuvoletta Verde', 'Installa OpenVPN*', 'Installa BarTender*', 'Installa AS400', 'Utilità' ) | ForEach-Object { [void]$menu.Items.Add($_) } $btn = New-WizardPrimaryButton -Text "Esegui" Add-WizardFooterButtons -FooterPanel $mainShell.FooterPanel -Buttons @($btn) $btn.Add_Click({ switch ($menu.SelectedIndex) { 0 { Action-InstallSiacloud } 1 { Action-InstallNuvoletta } 2 { Action-InstallOpenVPN } 3 { Action-InstallBarTender } 4 { Action-As400 } 5 { Action-Utilities } default { Show-Info "Seleziona un'azione." } } }) Add-WizardContentFullList -ContentPanel $mainShell.ContentPanel -ListControl $menu $form.Add_Shown({ param($sender, $e) if ($menu.Items.Count -gt 0) { $menu.TopIndex = 0 $menu.SelectedIndex = 0 } }) [void]$form.ShowDialog()