90 lines
3.0 KiB
PowerShell
90 lines
3.0 KiB
PowerShell
# RustDesk 配置自动导入脚本
|
|
# 用法:以管理员身份运行 PowerShell,然后执行此脚本
|
|
|
|
param(
|
|
[string] = "C:\Users\12914\AppData\Roaming\RustDesk\config"
|
|
)
|
|
|
|
Write-Host "RustDesk 配置导入工具" -ForegroundColor Green
|
|
Write-Host "=====================" -ForegroundColor Green
|
|
|
|
# 检查RustDesk是否在运行
|
|
$rustdeskProcess = Get-Process -Name "rustdesk" -ErrorAction SilentlyContinue
|
|
if ($rustdeskProcess) {
|
|
Write-Host "警告:RustDesk正在运行,需要先退出" -ForegroundColor Yellow
|
|
$response = Read-Host "是否强制结束RustDesk进程?(y/n)"
|
|
if ($response -eq 'y') {
|
|
Stop-Process -Name "rustdesk" -Force
|
|
Start-Sleep -Seconds 2
|
|
Write-Host "RustDesk已退出" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "请手动退出RustDesk后重新运行此脚本" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
# 创建备份目录
|
|
$backupDir = "$RustDeskPath\..\config_backup_20260824_224929"
|
|
if (Test-Path $RustDeskPath) {
|
|
Write-Host "备份原有配置到:$backupDir" -ForegroundColor Yellow
|
|
Copy-Item -Path $RustDeskPath -Destination $backupDir -Recurse -Force
|
|
Write-Host "备份完成" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "原有配置目录不存在,跳过备份" -ForegroundColor Yellow
|
|
}
|
|
|
|
# 确保目标目录存在
|
|
if (!(Test-Path $RustDeskPath)) {
|
|
New-Item -ItemType Directory -Path $RustDeskPath -Force | Out-Null
|
|
New-Item -ItemType Directory -Path "$RustDeskPath\peers" -Force | Out-Null
|
|
}
|
|
|
|
# 获取脚本所在目录(假设配置文件在同级目录)
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$sourceConfig = "$scriptDir\config"
|
|
|
|
if (!(Test-Path $sourceConfig)) {
|
|
Write-Host "错误:找不到配置文件目录 $sourceConfig" -ForegroundColor Red
|
|
Write-Host "请确保此脚本与config文件夹在同一目录" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# 复制配置文件
|
|
Write-Host "复制配置文件..." -ForegroundColor Cyan
|
|
$files = @(
|
|
"RustDesk.toml",
|
|
"RustDesk2.toml",
|
|
"RustDesk_local.toml",
|
|
"peers.toml",
|
|
"RustDesk_default.toml"
|
|
)
|
|
|
|
foreach ($file in $files) {
|
|
$sourceFile = "$sourceConfig\$file"
|
|
$destFile = "$RustDeskPath\$file"
|
|
if (Test-Path $sourceFile) {
|
|
Copy-Item -Path $sourceFile -Destination $destFile -Force
|
|
Write-Host " ✓ $file" -ForegroundColor Green
|
|
} else {
|
|
Write-Host " ✗ $file (未找到)" -ForegroundColor Red
|
|
}
|
|
}
|
|
|
|
# 复制peers目录
|
|
$peersSource = "$sourceConfig\peers"
|
|
$peersDest = "$RustDeskPath\peers"
|
|
if (Test-Path $peersSource) {
|
|
if (!(Test-Path $peersDest)) {
|
|
New-Item -ItemType Directory -Path $peersDest -Force | Out-Null
|
|
}
|
|
Copy-Item -Path "$peersSource\*" -Destination $peersDest -Recurse -Force
|
|
Write-Host " ✓ peers目录" -ForegroundColor Green
|
|
}
|
|
|
|
Write-Host "
|
|
配置导入完成!" -ForegroundColor Green
|
|
Write-Host "现在可以启动RustDesk,应该会显示原来的设备ID和密码。" -ForegroundColor Cyan
|
|
Write-Host "
|
|
按任意键退出..." -ForegroundColor Gray
|
|
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
|