Skip to content

Instantly share code, notes, and snippets.

@noahpeltier
Created July 18, 2024 16:15
Show Gist options
  • Save noahpeltier/fd033fa310003ca7a2cdbd4a183846fb to your computer and use it in GitHub Desktop.
Save noahpeltier/fd033fa310003ca7a2cdbd4a183846fb to your computer and use it in GitHub Desktop.
begin {
function Find-UninstallKey {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline)]
[String]$DisplayName,
[Parameter()]
[Switch]$UninstallString
)
process {
$UninstallList = New-Object System.Collections.Generic.List[Object]
$Result = Get-ChildItem HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Get-ItemProperty |
Where-Object { $_.DisplayName -like "*$DisplayName*" }
if ($Result) { $UninstallList.Add($Result) }
$Result = Get-ChildItem HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Get-ItemProperty |
Where-Object { $_.DisplayName -like "*$DisplayName*" }
if ($Result) { $UninstallList.Add($Result) }
# Programs don't always have an uninstall string listed here so to account for that I made this optional.
if ($UninstallString) {
# 64 Bit
$UninstallList | Select-Object -ExpandProperty UninstallString -ErrorAction Ignore
}
else {
$UninstallList
}
}
}
function Invoke-Download {
param(
[Parameter()]
[String]$URL,
[Parameter()]
[String]$Path,
[Parameter()]
[int]$Attempts = 3,
[Parameter()]
[Switch]$SkipSleep
)
Write-Host "URL given, Downloading the file..."
$i = 1
While ($i -le $Attempts) {
# Some cloud services have rate-limiting
if (-not ($SkipSleep)) {
$SleepTime = Get-Random -Minimum 3 -Maximum 15
Write-Host "Waiting for $SleepTime seconds."
Start-Sleep -Seconds $SleepTime
}
if ($i -ne 1) { Write-Host "" }
Write-Host "Download Attempt $i"
try {
# Invoke-WebRequest is preferred because it supports links that redirect, e.g., https://t.ly
if ($PSVersionTable.PSVersion.Major -lt 4) {
# Downloads the file
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($URL, $Path)
}
else {
# Standard options
$WebRequestArgs = @{
Uri = $URL
OutFile = $Path
MaximumRedirection = 10
UseBasicParsing = $true
}
# Downloads the file
Invoke-WebRequest @WebRequestArgs
}
$File = Test-Path -Path $Path -ErrorAction SilentlyContinue
}
catch {
Write-Warning "An error has occurred while downloading!"
Write-Warning $_.Exception.Message
if (Test-Path -Path $Path -ErrorAction SilentlyContinue) {
Remove-Item $Path -Force -Confirm:$false -ErrorAction SilentlyContinue
}
$File = $False
}
if ($File) {
$i = $Attempts
}
else {
Write-Warning "File failed to download."
Write-Host ""
}
$i++
}
if (-not (Test-Path $Path)) {
Write-Error -Message "Failed to download file!" -Category InvalidResult -Exception (New-Object System.Deployment.Application.DeploymentDownloadException)
exit 1
}
}
function Set-AcrobatReadOnlyMode {
# Define the registry paths
$baseKeyPath = "HKLM:\SOFTWARE\Policies\Adobe\Adobe Acrobat\DC\FeatureLockDown"
$cIPMKeyPath = "$baseKeyPath\cIPM"
# Ensure the base key path exists
if (-not (Test-Path -Path $baseKeyPath)) {
New-Item -Path $baseKeyPath -Force | Out-Null
}
# Add the bIsSCReducedModeEnforcedEx value
New-ItemProperty -Path $baseKeyPath -Name "bIsSCReducedModeEnforcedEx" -PropertyType DWORD -Value 1 -Force | Out-Null
# Create the cIPM key if it doesn't exist
if (-not (Test-Path -Path $cIPMKeyPath)) {
New-Item -Path $cIPMKeyPath -Force | Out-Null
}
# Add the bDontShowMsgWhenViewingDoc value under the cIPM key
New-ItemProperty -Path $cIPMKeyPath -Name "bDontShowMsgWhenViewingDoc" -PropertyType DWORD -Value 0 -Force | Out-Null
Write-Host "Registry values set successfully to configure Acrobat in read-only mode."
}
$AcrobatProDownloadLocation = (Join-Path $PSScriptRoot -ChildPath "AcrobatPro.zip")
$AcrobatProDownloadURL = "https://trials.adobe.com/AdobeProducts/APRO/Acrobat_HelpX/win32/Acrobat_DC_Web_x64_WWMUI.zip"
}
process {
$VerbosePreference = 'Continue'
$ErrorActionPreference = 'Stop'
# Detect existing installs
if ((Find-UninstallKey -DisplayName "Adobe Acrobat")) {
Write-Output "Acrobat already installed. Exiting script"
exit 0
}
# Downbload the required files
Write-Output "Acrobat install not detected, moving to install step"
try {
Invoke-Download -URL $AcrobatProDownloadURL -Path $AcrobatProDownloadLocation
}
catch {
Write-Output "Download step failed"
$_
exit 1
}
# Make sure our download is in the right place and extract
if (Test-Path $AcrobatProDownloadLocation) {
Write-Output "Extracting archive"
Expand-Archive $AcrobatProDownloadLocation -DestinationPath $PSScriptRoot
}
if (-not (Test-Path "$PSscriptroot\Adobe Acrobat")) {
Write-Output "Could not find exctracted files"
exit 1
}
Write-Output "Waiting 5 seconds"
Start-Sleep -Seconds 5
# Install the MSI
Write-Output "Runing install step"
$MSIInstallArguments = @('/i', """$PSScriptRoot\Adobe Acrobat\AcroPro.msi""", '/quiet', '/norestart', '/L*V', """$PSScriptRoot\AcrobatProInstall.log""")
Start-Process msiexec.exe -ArgumentList $MSIInstallArguments -wait -Verb RunAs
#msiexec.exe /i "$PSScriptRoot\Adobe Acrobat\AcroPro.msi" /quiet /norestart /L*V "$PSScriptRoot\AcrobatPro.log"
}
end {
# Make sure it was installed
if ((Find-UninstallKey -DisplayName "Adobe Acrobat")) {
Write-Output "Adobe Acrobat Pro installed successfully."
if ($env:readerOnly) {
Set-AcrobatReadOnlyMode
}
# Clean up after ourselves
Remove-Item "$PSScriptRoot\Adobe Acrobat" -Recurse -Force
Remove-Item $AcrobatProDownloadLocation -Force
exit 0
}
else {
Write-Output "Adobe Acrobat Pro failed to install successfully."
Write-Output "Please see the logfile at $("$PSScriptRoot\AcrobatProInstall.log")"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment