Skip to content

Instantly share code, notes, and snippets.

@exurd
Last active August 12, 2025 15:53
Show Gist options
  • Select an option

  • Save exurd/f236f374515905513e9de6e2cba334cb to your computer and use it in GitHub Desktop.

Select an option

Save exurd/f236f374515905513e9de6e2cba334cb to your computer and use it in GitHub Desktop.
Powershell script for Windows Sandbox that installs every Visual C++ Redistributable via VisualCppRedist AIO Pack by abbodi1406. Recommended if you're frequently running older programs.
param(
# Keep Smart App Control off after installing the redists
[switch]$keepSmartAppControlOff
)
# URLs for the latest Visual C++ Redistributables (https://github.com/abbodi1406/vcredist)
$urls = @(
"https://github.com/abbodi1406/vcredist/releases/latest/download/VisualCppRedist_AIO_x86_x64.exe"
)
# VisualCppRedist AIO does not include any ARM64 installers,
# and it's not planned to have ARM64 support.
# https://github.com/abbodi1406/vcredist/issues/110
if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') {
$urls += "https://aka.ms/vs/17/release/vc_redist.arm64.exe"
}
# Directory to save the downloads
$downloadPath = "$env:TEMP"
# https://stackoverflow.com/a/25127597
Function Get-RedirectedUrl {
Param (
[Parameter(Mandatory=$true)]
[String]$URL
)
$request = [System.Net.WebRequest]::Create($URL)
$request.Method = "HEAD"
$request.AllowAutoRedirect=$false
$response=$request.GetResponse()
If ($response.StatusCode -eq "Found")
{
$response.GetResponseHeader("Location")
}
}
# To improve download performance, the progress bar is suppressed. [2, 6]
$ProgressPreference = 'SilentlyContinue'
# There is a bug that makes MSI installs take *FOREVER* to finish.
# https://github.com/microsoft/Windows-Sandbox/issues/68
# There is a solution: temporarily turn off Smart App Control.
# Thanks, Traxof63!
Function Set-SmartAppControl {
Param (
[Parameter(Mandatory=$true)]
[String]$Num
)
Write-Host "Setting CI Policy 'VerifiedAndReputablePolicyState' to $Num..."
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\CI\Policy" -Name "VerifiedAndReputablePolicyState" -Value $Num
# https://github.com/ThioJoe/Windows-Sandbox-Tools/blob/86683a433df7ce1373229ae3871c33bae40d71bf/Startup%20Scripts/SandboxStartup.ps1#L21
CiTool.exe --refresh --json | Out-Null
}
Set-SmartAppControl "0"
foreach ($url in $urls) {
$redirectUrl = [System.IO.Path]::GetFileName((Get-RedirectedUrl $url))
$fileName = $redirectUrl.Split('/')[-1]
$filePath = Join-Path $downloadPath $fileName
Write-Host "Downloading $fileName..."
# Download the file without a progress bar [1, 4]
Invoke-WebRequest -Uri $url -OutFile $filePath
if (Test-Path $filePath) {
Write-Host "Installing $fileName..."
# Silently install the redistributable and wait for it to complete [3, 5, 9]
if ($url -match "https://aka.ms/vs/17/release/vc_redist.arm64.exe") {
Start-Process -FilePath $filePath -ArgumentList "/install /quiet /norestart" -Wait
} else {
Start-Process -FilePath $filePath -ArgumentList "/ai" -Wait
}
Write-Host "$fileName has been installed."
# Optional: Remove the installer after installation
# Remove-Item -Path $filePath
} else {
Write-Host "Error: Failed to download $fileName."
}
}
if (!($keepSmartAppControlOff)) {
# Turn Smart App Control back on
Set-SmartAppControl "1"
}
# Restore the default progress preference
# (uncomment if appending this code to a bigger script)
# $ProgressPreference = 'Continue'
Write-Host "Script execution finished."
@exurd
Copy link
Author

exurd commented Aug 11, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment