Created
August 22, 2018 07:29
-
-
Save DXPetti/0f4f22884c57dc934b26a4dc314eeb55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.DESCRIPTION | |
Powershell script that prompts user to accept license followed by installation of font and license files | |
.PARAMETERS | |
None - execute directly from Powershell | |
.Version | |
1.3 | |
.Author | |
James Pettigrove | |
.Compatibility | |
Windows 7, Windows 10 | |
.Release Date | |
31/01/2017 | |
.Notes | |
v1.0, 20160131 - Initial Version | |
v1.1, 20160201 - Added job to dismiss overwrite file prompts when installing the fonts | |
v1.2, 20160201 - Swapped out previous install and skip overwriting method | |
v1.3, 20160301 - Changed install method again to one that is compatible down to PS2.0 | |
#> | |
## Load necessary assembly | |
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | |
## Vendor font license that will be displayed to the user for acceptence | |
$license = "LICENSE TEXT" | |
## Output License to user for acceptence | |
$output = [System.Windows.Forms.MessageBox]::Show("$license | |
Do you agree to the above Terms & Conditions?" | |
, "LICENSE NAME AND VERSION" , 4) | |
## If user accepts, continue | |
if ($output -eq "YES" ) | |
{ | |
## 0x14 is a special system folder pointer to the path where fonts live, and is needed below. | |
$fonts = 0x14 | |
## Path to font files | |
$fontsPath = ".\" | |
## Make a refrence to Shell.Application | |
$objShell = New-Object -ComObject Shell.Application | |
$objFolder = $objShell.Namespace($fonts) | |
## Used for debugging | |
$copyOptions = 4 + 16 | |
## Copy file in $($file.fullname) PS2.0 friendly format | |
$copyFlag = [String]::Format("{0:x}", $copyOptions) | |
## Loop through each directory in the specified path looking for font files | |
foreach($file in $(Get-ChildItem -Path $fontsPath -Include *.ttf,*.otf,*.fon,*.fnt -Recurse)) | |
{ | |
## Confirms font doesn't exist already before copying, if exists, don't copy | |
If (test-path "c:\windows\fonts\$($file.name)") | |
{} | |
Else | |
{ | |
$copyFlag = [String]::Format("{0:x}", $copyOptions) | |
$objFolder.CopyHere($file.fullname, $copyOptions) | |
} | |
} | |
## Copy license file to workstation to meet licensing terms | |
$licensePath = ".\LICENSEFILE.txt" | |
$licenseDestination = "$env:programfiles\VENDOR\FONT\LICENSEFILE.txt" | |
New-Item -ItemType File -Path $licenseDestination -Force | |
Copy-Item $licensePath $licenseDestination -Force | |
} | |
## If user does not accept, exit script | |
else | |
{ | |
Exit 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment