【发布时间】:2017-12-30 03:55:37
【问题描述】:
我写了一个通过cmd和C#安装字体的方法。 我的方法如下:
void installFont(string fontsFolderPath, string fontName)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = "cmd.exe";
String cc = @"/C copy " + fontsFolderPath + @" C:\Windows\Fonts" + "® ADD HKLM\\Software\\Microsoft\\Windows_NT\\CurrentVersion\\Fonts /v " + fontName + @" /t REG_SZ /d " + fontName + @".ttf /f &pause"; ;
startInfo.Arguments = cc;
process.StartInfo = startInfo;
process.Start();
}
但这不是添加它,我单独尝试了 cmd 指令,它可以正常工作,但是当我通过 C# 请求它们时它们不起作用。 我以管理员身份运行 VS。 我的代码中有什么错误,或者有什么更好的方法来完成这项工作。 先感谢您。
【问题讨论】:
-
这可能很大,但你有 "C:\windows\Fonts" + "®" 你的字体路径和你的注册表命令之间没有空格。它可能的 CMD 将其解释为一条连续路径。此外,我不确定您是否可以将所有这些作为 1 个参数运行,您可能必须重定向输入并单独编写命令。这是一个关于如何做到这一点的链接stackoverflow.com/questions/437419/…
-
我添加了空间,但它不起作用。
-
那么副本很可能将您的 reg 命令解释为它的开关,而不知道该怎么做。查看我发布的链接,特别是显示如何重定向输入的链接,以便您可以运行多个命令,就像它们是同一进程的新命令一样。
-
你能在启动进程时准确显示 cc 字符串是什么吗?
-
@PaulF 即 cc: /C 复制 C:\Folder\ C:\Windows\Fonts ® ADD HKLM\Software\Microsoft\Windows_NT\CurrentVersion\Fonts /v Libertinage /t REG_SZ /d Libertinage .ttf /f &暂停