Skip to content

Commit

Permalink
Update setup.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
xmt3061123 committed Jun 21, 2024
1 parent 9152d5f commit 8b00adc
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions setup.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
# 禁用防火墙
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
& {$P = $env:TEMP + '\chromeremotedesktophost.msi'; Invoke-WebRequest 'https://dl.google.com/edgedl/chrome-remote-desktop/chromeremotedesktophost.msi' -OutFile $P; Start-Process $P -Wait; Remove-Item $P}
& {$P = $env:TEMP + '\chrome_installer.exe'; Invoke-WebRequest 'https://dl.google.com/chrome/install/latest/chrome_installer.exe' -OutFile $P; Start-Process -FilePath $P -Args '/install' -Verb RunAs -Wait; Remove-Item $P}

# 定义下载和安装函数
function Download-And-Install {
param (
[string]$url,
[string]$fileName,
[string]$installArgs = ""
)

$tempPath = Join-Path -Path $env:TEMP -ChildPath $fileName
try {
Write-Output "Downloading $url to $tempPath"
Invoke-WebRequest -Uri $url -OutFile $tempPath -ErrorAction Stop
Write-Output "Starting installation of $fileName"
Start-Process -FilePath $tempPath -ArgumentList $installArgs -Verb RunAs -Wait -ErrorAction Stop
}
catch {
Write-Error "Failed to download or install $fileName: $_"
}
finally {
if (Test-Path $tempPath) {
Remove-Item $tempPath -Force
Write-Output "$fileName has been removed from temp"
}
}
}

# 使用后台作业并行下载和安装
$job1 = Start-Job -ScriptBlock {
Download-And-Install -url "https://dl.google.com/edgedl/chrome-remote-desktop/chromeremotedesktophost.msi" -fileName "chromeremotedesktophost.msi"
}

$job2 = Start-Job -ScriptBlock {
Download-And-Install -url "https://dl.google.com/chrome/install/latest/chrome_installer.exe" -fileName "chrome_installer.exe" -installArgs "/install"
}

# 等待所有作业完成
Wait-Job -Job $job1, $job2

# 输出作业结果
Receive-Job -Job $job1, $job2

# 清理作业
Remove-Job -Job $job1, $job2

0 comments on commit 8b00adc

Please sign in to comment.