1

So as the title describes, I have a font file registered in project resources as an embedded resource. I want to programmatically copy this font that is inside the .exe file, into Windows font folder (install it). Need to mention that I can't have the font file aside the .exe file because all of the project is integrated inside the .exe file and we can't have any other files around. And also I want to avoid administration permissions.

I have read the similar questions but non helped me! So, Any help would be appreciated.

yavarSt
  • 33
  • 6
  • That should be installer's business to update the registry and add an entry for that font. To do that manually, try [this](https://social.msdn.microsoft.com/Forums/en-US/f3fcf96f-b508-4a56-a280-ddbb8ca8e2ff/installing-fonts-programatically-c?forum=csharpgeneral). Consider the installer option. – dr.null Apr 13 '21 at 13:35
  • @dr.null , thank you for your attention, for the installer part, I don't want user to see that software doing something awkward, and about the link you shared, I saw this solution before and I know I can copy the file by it's path and then add a registry entry, but the problem is, my font's file is inside the `.exe` file and I can't give it's path because it would lead to `.exe` file. – yavarSt Apr 13 '21 at 19:04
  • Installing resources including fonts is not an awkward task. You could 1) extract the font stream from the resources and save it as font file. 2) or include the original font file in the installer to be deployed in the target machine instead of inserting it into the resources. Then you have the file, you know the rest. – dr.null Apr 14 '21 at 06:44
  • 1
    @dr.null Thank you for you advice, that stream solution seams more suitable for my project, I'll try that and let you know the outcome. – yavarSt Apr 15 '21 at 18:00
  • @dr.null The stream solution worked as I wanted, but now I have that access problem! when I try to copy font file into windows fonts folder and the app hasn't run as administrator, I get the access denied error. how can I bypass this error ?! and another problem is, when I run the app as administrator and font is getting installed, I still have to restart the app to see the installed font's impact. is there anyway to refresh font list or something ? And again I appreciate your help with this. – yavarSt Apr 15 '21 at 19:36
  • No problem you are welcome. That's what I tried to tell you in my first comment. You can't just copy the font file into the Fonts folder. You also need to add a registry entry for that font to be visible system-wide. – dr.null Apr 15 '21 at 19:58
  • Alternative: [PrivateFontCollection](https://stackoverflow.com/a/23658552/14171304). – dr.null Apr 15 '21 at 20:05
  • @dr.null I've used `privateFontCollection` in the project before and I can show control text with my font, but the thing is, this app produces Docx files that the text in it is also written with the same font and I want the font to be displayed when user opens the output Docx file. There for I have no choice but to install that custom font. – yavarSt Apr 15 '21 at 20:12
  • Yes you have to register the font to be used by the other apps. Read [this](https://stackoverflow.com/a/13530434/14171304) answer as a second opinion. – dr.null Apr 15 '21 at 20:16
  • @dr.null That is not the problem, I can install my font with administrator privileges (copying and registering). My problem now is that how to avoid prerequisite of administrator privilege. I guess I have no other choice but to let user to know and accept installing of the font! – yavarSt Apr 15 '21 at 20:30

0 Answers0