From 8b00adc972f86582a54807f0367418f74a39a281 Mon Sep 17 00:00:00 2001 From: xmt3061123 <71756356+xmt3061123@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:17:43 +0800 Subject: [PATCH] Update setup.ps1 --- setup.ps1 | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/setup.ps1 b/setup.ps1 index b5d0509..677b311 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -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