Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font installation for non-admin users #10

Closed
chawyehsu opened this issue May 21, 2019 · 4 comments · Fixed by #161
Closed

Font installation for non-admin users #10

chawyehsu opened this issue May 21, 2019 · 4 comments · Fixed by #161

Comments

@chawyehsu
Copy link

From Windows 10 17704 onward, Users have the ability to install fonts without admin rights.

As reference: https://blogs.windows.com/windowsexperience/2018/06/27/announcing-windows-10-insider-preview-build-17704/

@linyinfeng
Copy link

linyinfeng commented May 21, 2019

Updated again...
I retest the installer and uninstaller following on 1903 and find it is not working now. Last time I use these script is several months ago because my switching to other system(now I am back on win). Some Windows mechanism may be changed and it is no longer working. I am sorry for this wrong script.
The work can be done by replacing installer and uninstaller like this:

"installer": {
    "script": [
        "New-Item -Path 'HKCU:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\Scoop.%name' -Force | Out-Null",
        "Get-ChildItem `$dir -filter '*Windows Compatible.*' | ForEach-Object {",
        "    New-ItemProperty -Path 'HKCU:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\Scoop.%name' -Name `$_.Name -Value `$_.FullName -Force | Out-Null",
        "}"
    ]
},
"uninstaller": {
    "script": [
        "Remove-Item -Path 'HKCU:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\Scoop.%name'",
        "Write-Host \"The '`$(`$app.Replace('-NF', ''))' Font family has been uninstalled and will not be present after restarting your computer.\" -Foreground Magenta"
    ]
}

Changes made to registry will looks like this:
2019-05-21
Also, changes to fonts can be immediately viewed in Settings - Personalization - Fonts.

A problem is, the Windows Font Cache Service(FontCache) does not automatically detect changes of this registry key and the service does not update font cache at boot time by default to reduce boot time of Windows. A restart of FontCache service can fix missing of installed fonts, but this requires admin rights and a restart may not be a reliable way to accomplish this task. I don't find approaches to build font cache for newly added fonts without admin rights. This might cause problem.

My fork of the repository for my personal use installs fonts without admin rights: linyinfeng/scoop-nerd-fonts. I am not actively maintaining the fork and it may be buggy. But it can serves as a simple working example for the issue.

@chawyehsu
Copy link
Author

chawyehsu commented May 21, 2019

@linyinfeng Thanks for your information, this is really helpful!
@matthewjberger Would you like to adopt this to support non-admin installation? Maybe we should add conditions to check if the user's machine is under Windows 10 17704 or later, for backward compatibility.

@linyinfeng
Copy link

@h404bi I don't known whether or not fonts installed by the new method can be used by any application. In my test some application can not use these fonts. I believe that compatibility of the new installation method needs more inspection. Maybe both installation methods should be kept.

@linyinfeng
Copy link

linyinfeng commented May 22, 2019

Tried to copy fonts to AppData\Local\Microsoft\Windows\Fonts and modified registry keys. Installed fonts in this directory seem work well.
Font files not in the directory seems take effect when fonts cache was rebuilt and disappear after system reboot. So maybe we can't just leave font files in the app directory of scoop and only create registry keys for them like the script described above in my comment, which I thought is a nice and clean way.

Update:
I ignored permission problem. Fonts can not be accessed by service like FontCache because some services have no read permission to scoop apps directory. By properly set read rights for them in ACL, we can install fonts just in the default location of scoop.
A problem is to find out what ACL rules should be added to which files or directories to make font cache services and all applications including Font settings work.

jonz94 added a commit that referenced this issue Nov 27, 2021
Allow font installation for non-admin user

- Install fonts into user's font directory `$env:LOCALAPPDATA\Microsoft\Windows\Fonts` (administrator rights are **not** required)
    - This feature required Windows 10 version 1809 and above (build number >= `17763`)
    - Fallback to install fonts into system fonts directory `$env:windir\Fonts` if Windows version is before 1809 (administrator rights are required)

- Add support for scoop global installation (e.g. `scoop install -g SarasaGothic-ttc`)
    - When `-g` is provided, the fonts will be installed into system fonts directory `$env:windir\Fonts` (administrator rights are required)

- Remove `sudo` as dependency

And thanks to linyinfeng's information (#10 (comment)) for the inspiration of this commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants