安装字体ClickOnce但不是RunAsAdmin

时间:2013-11-21 06:57:29

标签: c# fonts

在我的项目使用字体中, 用于ClickOnce时安装字体。

string strFontsPathFile = Environment.GetEnvironmentVariable("windir")
                + @"\Fonts\" + strFileName;
File.Copy(strFontFilePath, strFontsPathFile, true);

//2)Step 2 : Install font in resource of MS-Windows
if (AddFontResource(strFontsPathFile) == 0)
   return false;

//3)Step 3 : Set registry information of new installed font for use
RegistryKey reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", true);
reg.SetValue(strFileName.Split('.')[0] + " (TrueType)", strFileName);
reg.Close();
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);

但错误:

  

拒绝访问路径''。

1 个答案:

答案 0 :(得分:0)

如果您的字体不需要在多个应用程序之间共享,您可以尝试私有字体部署,而不是在操作系统中安装它们。在这种情况下,您的应用不需要使用管理员帐户。

私人开发有一个很好的解决方案:Embedding/deploying custom font in .NET app