0

I am running the following commands through a .bat file:

copy "SoleSurvivor.ttf" "%SYSTEMROOT%\fonts"
copy "SoleSurvivor.ttf" "%USERPROFILE%\AppData\Local\Microsoft\Windows\Fonts"
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Sole Survivor (TrueType)" /t REG_SZ /d SoleSurvivor.ttf /f

Even though the registry is edited correctly and the file SoleSurvivor.ttf is copied to %USERPROFILE%\AppData\Local\Microsoft\Windows\Fonts, the font is not installed.

Why is not working and what can I do?

  • What you can do? You could explain what you mean with "not working" because of that is not an error description. You could also look on the results of the Stack Overflow search [[batch-file\] install font*](https://stackoverflow.com/search?q=%5Bbatch-file%5D+install+font*). – Mofi Aug 21 '23 at 17:49
  • BTW: There is the predefined [Windows environment variable](https://en.wikipedia.org/wiki/Environment_variable#Windows) `LOCALAPPDATA` for the directory path referenced by your code with `%USERPROFILE%\AppData\Local`. There is no directory `%USERPROFILE%\AppData\Local\Microsoft\Windows\Fonts` on my Windows PC. The second command line creates for that reason the __file__ `Fonts` as copy of `SoleSurvivor.ttf` in the existing directory `%LOCALAPPDATA%\Microsoft\Windows` which would not make me happy. Check the existence of directories first or at least let directory paths end with ``\``. – Mofi Aug 21 '23 at 17:54
  • PS: You know that `copy "SoleSurvivor.ttf" "%SystemRoot%\fonts"` and `reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Sole Survivor (TrueType)" /t REG_SZ /d SoleSurvivor.ttf /f` require the execution of the batch file __as administrator__ because of a standard user account has no permissions to copy files into any Windows directory or added registry values to most keys under `HKEY_LOCAL_MACHINE`. – Mofi Aug 21 '23 at 17:59
  • PPS: `"SoleSurvivor.ttf"` should be also modified to `"%~dp0SoleSurvivor.ttf"` to reference the TTF file with full __batch file directory path__ and not with a path relative to __current directory__ which can be any directory on batch file execution, especially on using __Run as administrator__, see [Why does 'Run as administrator' change (sometimes) batch file's current directory?](https://stackoverflow.com/a/31655249/3074564) – Mofi Aug 21 '23 at 18:02

0 Answers0