# install.ps1 - IT Enterprise Safe Windows Tray App installer # Copies the compiled .exe to Program Files and sets up auto-start # Usage: Run as Administrator: .\install.ps1 [-Uninstall] param( [switch]$Uninstall ) $ErrorActionPreference = "Stop" $appName = "ITEnterpriseSafe" $displayName = "IT Enterprise Safe" $installDir = "C:\Program Files\ITEnterprise\Safe" $exeName = "ITEnterpriseSafe.exe" $registryPath = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" $registryKey = "ITEnterpriseSafe" # --- Uninstall --- if ($Uninstall) { Write-Host "Uninstalling $displayName..." -ForegroundColor Yellow # Stop running instance $proc = Get-Process -Name $appName -ErrorAction SilentlyContinue if ($proc) { Write-Host "Stopping running instance..." $proc | Stop-Process -Force Start-Sleep -Seconds 1 } # Remove auto-start registry entry if (Get-ItemProperty -Path $registryPath -Name $registryKey -ErrorAction SilentlyContinue) { Remove-ItemProperty -Path $registryPath -Name $registryKey -Force Write-Host "Removed auto-start registry entry." -ForegroundColor Green } # Remove installed files if (Test-Path $installDir) { Remove-Item -Path $installDir -Recurse -Force Write-Host "Removed installation directory: $installDir" -ForegroundColor Green } # Remove stored credentials from Windows Credential Manager Write-Host "Clearing stored session token from Credential Manager..." try { cmdkey /delete:ITEnterpriseSafe 2>$null } catch { } Write-Host "" Write-Host "$displayName has been uninstalled." -ForegroundColor Green exit 0 } # --- Install --- Write-Host "Installing $displayName..." -ForegroundColor Cyan Write-Host "" # Locate the compiled .exe $sourceExe = Join-Path $PSScriptRoot $exeName if (-not (Test-Path $sourceExe)) { Write-Host "ERROR: $exeName not found in script directory." -ForegroundColor Red Write-Host "Run build.ps1 first to compile the application." -ForegroundColor Yellow exit 1 } # Stop any running instance before copying $proc = Get-Process -Name $appName -ErrorAction SilentlyContinue if ($proc) { Write-Host "Stopping running instance..." $proc | Stop-Process -Force Start-Sleep -Seconds 1 } # Create installation directory if (-not (Test-Path $installDir)) { New-Item -Path $installDir -ItemType Directory -Force | Out-Null Write-Host "Created directory: $installDir" } # Copy executable Copy-Item -Path $sourceExe -Destination (Join-Path $installDir $exeName) -Force Write-Host "Copied $exeName to $installDir" -ForegroundColor Green # Set up auto-start via registry (current user, no admin required) $exePath = Join-Path $installDir $exeName Set-ItemProperty -Path $registryPath -Name $registryKey -Value "`"$exePath`"" -Type String Write-Host "Added auto-start registry entry (HKCU\Run)" -ForegroundColor Green # Start the application Write-Host "" Write-Host "Starting $displayName..." Start-Process -FilePath $exePath Start-Sleep -Seconds 2 # Verify it is running $running = Get-Process -Name $appName -ErrorAction SilentlyContinue if ($running) { Write-Host "" Write-Host "============================================" -ForegroundColor Green Write-Host " $displayName installed successfully!" -ForegroundColor Green Write-Host "============================================" -ForegroundColor Green Write-Host "" Write-Host " Location: $exePath" Write-Host " Auto-start: Enabled (current user)" Write-Host " Hotkey: Ctrl+Shift+S (search vault)" Write-Host " Tray icon: Shield icon in system tray" Write-Host "" Write-Host " Right-click the tray icon to get started." Write-Host " On first use, you will be prompted to authenticate." Write-Host "" Write-Host " To uninstall: .\install.ps1 -Uninstall" -ForegroundColor Gray } else { Write-Host "WARNING: Application may not have started correctly." -ForegroundColor Yellow Write-Host "Try running manually: $exePath" }