$ErrorActionPreference = "Stop" # ========================================================= # IRSA Remote Support Installer # Version: 1.0.1 # ========================================================= $RustDeskVersion = "1.4.9" $Installer = Join-Path ` $PSScriptRoot ` "rustdesk-$RustDeskVersion-x86_64.exe" $RustDeskExe = "C:\Program Files\RustDesk\rustdesk.exe" $SourceConfig = Join-Path ` $PSScriptRoot ` "RustDesk2.toml" $ConfigDir = Join-Path ` $env:APPDATA ` "RustDesk\config" $TargetConfig = Join-Path ` $ConfigDir ` "RustDesk2.toml" $LogDir = "C:\ProgramData\IRSA-Remote" $LogFile = Join-Path $LogDir "install.log" # ========================================================= # Administrator check # ========================================================= $CurrentUser = New-Object Security.Principal.WindowsPrincipal( [Security.Principal.WindowsIdentity]::GetCurrent() ) if (-not $CurrentUser.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator )) { Write-Host "Administrator privileges are required." Write-Host "Restarting installer as Administrator..." Start-Process ` powershell.exe ` -Verb RunAs ` -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" exit } # ========================================================= # Logging # ========================================================= New-Item ` -ItemType Directory ` -Path $LogDir ` -Force | Out-Null Start-Transcript ` -Path $LogFile ` -Append try { Write-Host "" Write-Host "==========================================" Write-Host " IRSA Remote Support Installer" Write-Host " Version 1.0.1" Write-Host "==========================================" Write-Host "" Write-Host "Current user: $env:USERNAME" Write-Host "PowerShell user profile: $env:USERPROFILE" Write-Host "APPDATA: $env:APPDATA" Write-Host "" # ===================================================== # Validate package files # ===================================================== Write-Host "Checking installation files..." if (-not (Test-Path $Installer)) { throw "RustDesk installer not found: $Installer" } if (-not (Test-Path $SourceConfig)) { throw "RustDesk2.toml not found: $SourceConfig" } Write-Host "Required files found." Write-Host "" # ===================================================== # Install RustDesk # ===================================================== Write-Host "Installing RustDesk $RustDeskVersion..." Start-Process ` -FilePath $Installer ` -ArgumentList "--silent-install" # RustDesk silent installer may keep a process alive, # therefore we don't use -Wait here. Start-Sleep -Seconds 15 if (-not (Test-Path $RustDeskExe)) { throw "RustDesk installation failed. Executable not found: $RustDeskExe" } Write-Host "RustDesk installed successfully." Write-Host "" # ===================================================== # Stop RustDesk before modifying configuration # ===================================================== Write-Host "Stopping RustDesk processes..." Stop-Process ` -Name rustdesk ` -Force ` -ErrorAction SilentlyContinue Start-Sleep -Seconds 3 # ===================================================== # Create configuration directory # ===================================================== Write-Host "Preparing RustDesk configuration directory..." New-Item ` -ItemType Directory ` -Path $ConfigDir ` -Force | Out-Null # ===================================================== # Backup existing configuration # ===================================================== if (Test-Path $TargetConfig) { $Timestamp = Get-Date -Format "yyyyMMdd-HHmmss" $BackupConfig = Join-Path ` $ConfigDir ` "RustDesk2-backup-$Timestamp.toml" Copy-Item ` -Path $TargetConfig ` -Destination $BackupConfig ` -Force Write-Host "Existing configuration backed up:" Write-Host $BackupConfig Write-Host "" } # ===================================================== # Deploy IRSA configuration # ===================================================== Write-Host "Deploying IRSA RustDesk configuration..." Copy-Item ` -Path $SourceConfig ` -Destination $TargetConfig ` -Force # ===================================================== # Verify configuration # ===================================================== if (-not (Test-Path $TargetConfig)) { throw "RustDesk configuration deployment failed." } $SourceHash = Get-FileHash ` $SourceConfig ` -Algorithm SHA256 $TargetHash = Get-FileHash ` $TargetConfig ` -Algorithm SHA256 Write-Host "Config destination:" Write-Host $TargetConfig Write-Host "" Write-Host "Source config SHA256:" Write-Host $SourceHash.Hash Write-Host "" Write-Host "Installed config SHA256:" Write-Host $TargetHash.Hash if ($SourceHash.Hash -ne $TargetHash.Hash) { throw "Configuration verification failed. SHA256 mismatch." } Write-Host "" Write-Host "Configuration verified successfully." Write-Host "" # ===================================================== # Check RustDesk service # ===================================================== Write-Host "Checking RustDesk Windows service..." $Service = Get-Service ` -Name "RustDesk" ` -ErrorAction SilentlyContinue if ($Service) { Write-Host "RustDesk service found." Write-Host "Service status: $($Service.Status)" if ($Service.Status -ne "Running") { Write-Host "Starting RustDesk service..." Start-Service ` -Name "RustDesk" ` -ErrorAction SilentlyContinue Start-Sleep -Seconds 3 $Service = Get-Service ` -Name "RustDesk" ` -ErrorAction SilentlyContinue Write-Host "Service status: $($Service.Status)" } } else { Write-Host "RustDesk service was not detected." Write-Host "Desktop mode will still be tested." } Write-Host "" # ===================================================== # Start RustDesk # ===================================================== Write-Host "Starting RustDesk..." Start-Process ` -FilePath $RustDeskExe Start-Sleep -Seconds 5 # ===================================================== # Final check # ===================================================== if (Get-Process rustdesk -ErrorAction SilentlyContinue) { Write-Host "RustDesk process is running." } else { Write-Host "Warning: RustDesk process not detected." } Write-Host "" Write-Host "==========================================" Write-Host " IRSA Remote Support setup completed" Write-Host "==========================================" Write-Host "" Write-Host "Log file:" Write-Host $LogFile Write-Host "" } catch { Write-Host "" Write-Host "==========================================" Write-Host " INSTALLATION FAILED" Write-Host "==========================================" Write-Host "" Write-Host $_.Exception.Message Write-Host "" Write-Host "Log file:" Write-Host $LogFile Write-Host "" exit 1 } finally { Stop-Transcript }