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 f438c6e commit 16ceec8
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,44 @@
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False

# 定义下载和安装函数
function Download-And-Install {
$scriptBlock = {
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"
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"
Download-And-Install -url $using:url -fileName $using:fileName -installArgs $using:installArgs
}

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

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

0 comments on commit 16ceec8

Please sign in to comment.