Liviu
Posts: 1026
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Font installation for non-admin users

Thu Feb 02, 2023 1:46 pm

Hello guys,

Currently our Register font support works only for packages with Administrator privileges. If the package is "Per user only" then the font registration fails. The same case applies when you have a "Per-machine if user is administrator, per-user otherwise" installation type and the user choose to select the "Only for me" option (Per-user install). Fonts are usually in the C:\Windows\Fonts directory. Which requires administrative privileges to alter.

However, Microsoft supports installing fonts without privileges. As of Windows 10 version 1803 (released in April 2018), non-admin font installation was added.

Installing fonts in Windows without administrative privileges results in the font being installed as a user font, not as a system-wide font. Doing this via a script automatically chooses the right folder if it didn’t have the necessary privileges. That is, other people can not use the fonts installed by other non-administrators after they log in.

Therefore, you can choose to install your font using our custom action support (the font will be automatically redirected based on the user privileges). To do this, you need to follow the steps below:

1. You have a "Per-machine if user is administrator, per-user otherwise" or "Per-user" installation type.

For a per-machine installation you can use our register font support.
installation type.png
installation type.png (73.97KiB)Viewed 258659 times

2. Add your font as a temporary file using the Add Temporary Files toolbar button on the Files and Folders page.
TempFile.png
TempFile.png (144KiB)Viewed 258659 times

Unlike Advanced Installer's regular files or resources, Temporary Files are copied on the target machine at the beginning of the installation and are deleted at the end of it.

3. Right click on the font file --> Properties option and save/note the property. We will use this later in our script.
property.png
property.png (81.6KiB)Viewed 258659 times

4. Now we need to install the font using a script. You can do that using a PowerShell script or a VBScript. In this tutorial we will use a VBScript. Just go to the Custom Actions page and add a new Execute inline script code custom action with sequence.

5. On the Action data field add the font property from step (3).
    • Action data: [AI_HUGAMOUR.TTF]
    6. The script code:

    Code: Select all

    dim actionData
    Const FONTS = &H14&
    
    actionData = Session.Property("CustomActionData")
    
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(FONTS)
    objFolder.CopyHere actionData
    The script begins by declaring a variable named "actionData" and by defining a constant named "FONTS" with a value of &H14&. This constant is used to determine the location of the "Fonts folder".

    Then, we retrieve the "CustomActionData" value and store it in the actionData variable. CustomActionData is an elegant way of accessing installer properties when using a Deferred Custom Action.

    The script then creates an instance of the "Shell.Application" object and uses it to bind to the Fonts folder by calling the "Namespace" method and passing the "FONTS" constant as a parameter.

    Finally, the "CopyHere" method is called on the "objFolder" object, with the path to the font file to be installed (in our case the path of our temporary file retrieved in the actionData variable) specified as an argument.

    This installs the font into the Fonts folder. By using the constant for the Fonts folder instead of a hardcoded path, the script ensures that it will always be able to locate the Fonts folder, regardless of its location on the system.

    The script is able to select the appropriate folder based on the user's privileges.

    7. Schedule the custom action to run When the system is being modified (deferred) under the Execution Time section.

    8. Uncheck the Uninstall and Maintenance options from the Execution Stage Condition section.
    custom action.png
    custom action.png (138.6KiB)Viewed 258659 times

    The sample project related to this sample is available for download as an attachment. If you would like to review the project, feel free to download the file.

    I hope this is helpful! We are here to help, so don't hesitate to reach out if you have any questions.

    Best regards,
    Liviu
    Attachments
    per user font sample.zip
    (29.14KiB)Downloaded 1495 times
    ________________________________________
    Liviu Sandu - Advanced Installer Team
    Follow us: Twitter - Facebook - YouTube

    Return to “Sample Projects”