Create an Unattended Deployment of Visual C++ 2010 Runtime
$cwd = Split-Path $script:MyInvocation.MyCommand.Path
$location = "$cwd\Visual C++ Runtime\2010"
# Create Folder Structure
Write-Debug "Creating Folder Structure..."
# Check if path exists
if( ( Test-Path "$location" -PathType Container ) -ne $true ) {
# It doesn't exist, so create it.
$created = New-Item "$location" -ItemType Directory
# If creation failed, we can't continue
if( $created -eq $false ) {
Write-Debug "Cannot create folder $location."
return $created
}
}
Set-Location "$location"
# Download files
$source_x86 = "http://download.microsoft.com/download/5/B/C/5BC5DBB3-652D-4DCE-B14A-475AB85EEF6E/vcredist_x86.exe"
$dest_x86 = "$location\vcredist_x86.exe"
$source_x64 = "http://download.microsoft.com/download/3/2/2/3224B87F-CFA0-4E70-BDA3-3DE650EFEBA5/vcredist_x64.exe"
$dest_x64 = "$location\vcredist_x64.exe"
Write-Debug "Downloading Redistributable Packages..."
try {
$wc = New-Object System.Net.WebClient
# If x86 package hasn't been downloaded, do it now.
if( (Test-Path $dest_x86 -PathType Leaf ) -eq $false ) {
Write-Debug "Downloadloading x86 package..."
$wc.DownloadFile($source_x86, $dest_x86)
} else {
Write-Debug "x86 already downloaded, skipping..."
}
# It x64 package isn't already downloaded, do it now.
if( (Test-Path $dest_x64 -PathType Leaf ) -eq $false ) {
Write-Debug "Downloading x64 package..."
$wc.DownloadFile($source_x64, $dest_x64)
} else {
Write-Debug "x64 package already downloaded, skipping..."
}
} catch [Exception] {
# Bad things happened while downloading.
Write-Debug $_.Exception.Message
return $_.Exception.Message
}
Write-Debug "Extracting x86 package..."
# Extract the x86 package to it's own directory.
$ext_x86 = "$location\x86"
if( (Test-Path $ext_x86 -PathType Container ) -eq $false ) {
Write-Debug "Extracting x86 package to $ext_x86..."
$ext_x86_ec = (Start-Process -FilePath "$dest_x86" -ArgumentList " /extract:`"$ext_x86`" /q" -Wait -Passthru).ExitCode
if( $ext_x86_ec -ne 0 ) {
Write-Debug "Failed to extract x86 package. Error code $ext_x86_ec"
return $ext_x86_ec
}
} else {
Write-Debug "$ext_x86 already exists, skipping x86 extraction."
}
# Extract the x64 package to it's own directory.
$ext_x64 = "$location\x64"
if( (Test-Path $ext_x64 -PathType Container ) -eq $false ) {
Write-Debug "Extracting x64 package to $ext_x64..."
$ext_x64_ec = (Start-Process -FilePath "$dest_x64" -ArgumentList " /extract:`"$ext_x64`" /q" -Wait -Passthru).ExitCode
if( $ext_x64_ec -ne 0 ) {
Write-Debug "Failed to extract x64 package. Error code $ext_x64_ec"
return $ext_x64_ec
}
} else {
Write-Debug "$ext_x64 already exists, skipping x64 extraction."
}
Write-Debug "Creating unattended install script..."
$uanttend_script = "$location\unattend.ps1"
if( (Test-Path $script -PathType Leaf) -ne $true ) {
# Create File
New-Item $uanttend_script -ItemType file | Out-Null
Write-Output "`$cwd = Split-Path `$script:MyInvocation.MyCommand.Path;`r`nStart-Process -FilePath `"`$cwd\x86\Setup.exe`" -ArgumentList `"/passive`" -Wait -Passthru;`r`nStart-Process -FilePath `"`$cwd\x64\Setup.exe`" -ArgumentList `"/passive`" -Wait -Passthru;" | Out-File $uanttend_script
} else {
Write-Debug "Unattended install script $uanttend_script already exists. Skipping."
}