Install Barcode Fonts with Powershell

This article illustrates using PowerShell to install True Type Barcode Fonts from ConnectCode on Microsoft Windows OS. The basic steps involve using Windows Terminal to copy the barcode fonts into "C:\Windows\Fonts" folder and then setting up RegEdit settings to make the fonts available to all users in Windows.

What is PowerShell?

PowerShell is a task automation and configuration management solution from Microsoft, consisting of a command-line shell tool and an associated scripting language.

Types of Installation


Install Barcode Fonts on Microsoft Windows for CURRENT WINDOWS USER

1. Launch the Terminal app from the Windows Start Menu.

2. In Terminal, run Windows PowerShell as Administrator. The screenshot below illustrates how to run PowerShell as Administrator.


3. Set up the appropriate Execution Policy in PowerShell. If you are testing on your local PC, you can set the Execution Policy to Unrestricted as shown below. Please set the appropriate policy for a Production machine.


      PS C:\Users\james\Desktop\scripts> Set-ExecutionPolicy -ExecutionPolicy Unrestricted

4. ConnectCode Barcode Fonts package comes with True Type, Open Type, and WOFF/WOFF2 barcode fonts. The following is a script to install ConnectCode True Type Barcode Fonts in the "C:\Program Files (x86)\ConnectCodeTrial" folder. You can first save a copy of the script below as PowerShellBarcodeFontsInstallation.ps1. The script below copies the fonts into the C:\Windows\Fonts folder.

      
      # Run this Powershell script to install ConnectCode Barcode Fonts from C:\Program Files (x86)\ConnectCodeTrial
      # https://www.barcoderesource.com
      
      $BarcodeDir         = "C:\Program Files (x86)\ConnectCodeTrial"
      $BarcodeFonts       = "C:\Program Files (x86)\ConnectCodeTrial\*"
      $Destination        = (New-Object -ComObject Shell.Application).Namespace(0x14)
      $TempBarcodeFolder  = "C:\Windows\Temp\BarcodeFonts"
      
      New-Item -ItemType Directory -Force -Path $BarcodeDir
      New-Item $TempBarcodeFolder -Type Directory -Force | Out-Null
      
      Get-ChildItem -Path $BarcodeFonts -Include '*.ttf','*.ttc','*.otf' | ForEach {
          If (-not(Test-Path "C:\Windows\Fonts\$($_.Name)")) {
              $Font = "$TempBarcodeFolder\$($_.Name)"        
              Copy-Item $($_.FullName) -Destination $TempBarcodeFolder      
              $Destination.CopyHere($Font,0x10)
              Remove-Item $Font -Force
          }
      }
      
      

5. Run the installation script with the following command in PowerShell.

      
         PS C:\Users\james\Desktop\scripts> .\PowerShellBarcodeFontsInstallation.ps1
   


You should see the following messages informing you on the installation of the True Type barcode fonts.


6. Once the PowerShell script completes execution, you can check the successful installation of the barcode fonts in Windows Font Settings. Simply scroll down on the list of fonts to find fonts in the ConnectCode package such as CCode39_S3_Trial (or CCode39_S3).


You can also launch Word or WordPad to check out the fonts availability. The screenshot below shows the CCode39_S3_Trial (ConnectCode39_S3_Trial.ttf) barcode font. You can now create a Code39 barcode by simply entering the text "*24682468*" and then setting the font to CCode39_S3_Trial (or CCode39_S3).

For other barcodes such as Code 128, you can use the font CCode128_S3, etc. Please note that some barcodes may require mandatory check digit characters. In this case, we recommend using our provided Font Encoder to generate the barcodes to ensure full compliance with ISO/GS1 specifications.


A free Barcode Software Encoder (Windows 10-11) is available on Microsoft App Store. This encoder app automatically detects all Trial, Registered, and 2D barcode fonts from ConnectCode and unlocks all the necessary encoding capabilities. Alternatively, a classic Barcode Fonts Encoder (windows 7 - 11) is available in the same folder of the fonts zipped file.

Encoder (Windows 10 - 11) - Microsoft Store

Encoder (Windows 7 - 11) - From the fonts zipped folder

Install Barcode Fonts on Microsoft Windows for ALL WINDOWS USERS

1. Launch the Terminal app from the Windows Start Menu.

2. In Terminal, run Windows PowerShell as Administrator. The screenshot below illustrates how to run PowerShell as Administrator.


3. Set up the appropriate Execution Policy in PowerShell. If you are testing on your local PC, you can set the Execution Policy to Unrestricted as shown below. Please set the appropriate policy for a Production machine.


      PS C:\Users\james\Desktop\scripts> Set-ExecutionPolicy -ExecutionPolicy Unrestricted

4. ConnectCode Barcode Fonts package comes with True Type, Open Type, and WOFF/WOFF2 barcode fonts. The following is a script to install ConnectCode True Type Barcode Fonts in the "C:\Program Files (x86)\ConnectCodeTrial" folder. You can first save a copy of the script below as PowerShellBarcodeFontsSystemWideInstallation.ps1. The script below copies the fonts into the C:\Windows\Fonts folder.

      
         # Run this Powershell script to install ConnectCode Barcode Fonts from C:\Program Files (x86)\ConnectCodeTrial for All Users in Windows
         # https://www.barcoderesource.com
         
            $BarcodeDir         = "C:\Program Files (x86)\ConnectCodeTrial"
            $SystemFontsPath    = "C:\Windows\Fonts"
         
            foreach($FontFile in Get-ChildItem $BarcodeDir -Include '*.ttf','*.ttc','*.otf' -recurse ) {
               $targetPath = Join-Path $SystemFontsPath $FontFile.Name
               if(Test-Path -Path $targetPath){
                  $FontFile.Name + " already installed"
               }
               else {
                  "Installing font " + $FontFile.Name
                  
                  #Extract Font information for Reqistry 
                  $ShellFolder = (New-Object -COMObject Shell.Application).Namespace($BarcodeDir)
                  $ShellFile = $ShellFolder.ParseName($FontFile.name)
                  $ShellFileType = $ShellFolder.GetDetailsOf($ShellFile, 2)
         
            
                  #Set the $FontType Variable
                  If ($ShellFileType -Like '*TrueType font file*') {$FontType = '(TrueType)'}
                              
                  #Update Registry and copy font to font directory
                  #$RegName = $ShellFolder.GetDetailsOf($ShellFile, 21) + ' ' + $FontType
                  #New-ItemProperty -Name $RegName -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" -PropertyType string -Value $FontFile.name -Force | out-null
             
                  New-ItemProperty -Name $FontFile.BaseName -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" -PropertyType string -Value $FontFile.name -Force | out-null
                  Copy-item $FontFile.FullName -Destination $SystemFontsPath
                  "Done"
               }
            }
      
      

5. Run the installation script with the following command in PowerShell.

      
         PS C:\Users\james\Desktop\scripts> .\PowerShellBarcodeFontsSystemWideInstallation.ps1
   

6. Once the PowerShell script completes execution, you can check the successful installation of the barcode fonts in Windows Font Settings. Simply scroll down on the list of fonts to find fonts in the ConnectCode package such as CCode39_S3_Trial (or CCode39_S3).


You can also launch Word or WordPad to check out the fonts availability. The screenshot below shows the CCode39_S3_Trial (ConnectCode39_S3_Trial.ttf) barcode font. You can now create a Code39 barcode by simply entering the text "*24682468*" and then setting the font to CCode39_S3_Trial (or CCode39_S3). For other barcodes such as Code 128, you can use the font CCode128_S3, etc. Please note that some barcodes may require mandatory check digit characters. In this case, we recommend using our provided Font Encoder to generate the barcodes to ensure full compliance with ISO/GS1 specifications.