1

I have c# web application project in which i want to install user uploaded .ttf font files into system.

I am using FontReg for the same. We can execute by using command line parameters as D:\TFS\Dev\Sprint_18_III\UI\Web\FontFiles>FontReg /copy so it will install all .ttf files present in directory

same this i am trying to achieve in c# code

using (Process process = new Process())
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.Verb = "runas";
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.FileName = "D:\\TFS\\Dev\\Sprint_18_III\\UI\\Web\\FontFiles\\FontReg.exe"; 
                startInfo.Arguments = "/copy";
                process.StartInfo = startInfo;
                process.Start();
                process.WaitForExit();
            }

Process gets completed but font doesn't install. What i am missing here ?

  • I dont want to give admin rights to entire web application running. It should be specific to one method only.
Shaggy
  • 5,422
  • 28
  • 98
  • 163
  • Is the working directory `D:` the directory you want it to search for fonts? – Nate Barbettini Dec 17 '15 at 16:00
  • 1
    Are you trying to add the font's on the client or the server? – Liam Dec 17 '15 at 16:01
  • I want to install it on server system – Shaggy Dec 17 '15 at 16:02
  • If yout app is hosted by IIS it is by default run under [restricted user account](http://stackoverflow.com/a/5731360/4074081) that is not allowed to make system-wide changes. – dewaffled Dec 17 '15 at 16:14
  • 4
    Installing a font on a server does not really help a client, unless you are doing some kind of remote desktop. – Scott Chamberlain Dec 17 '15 at 16:18
  • 1
    Does the process completed with or without error (check `Process.ExitCode`)? Because I'm pretty much sure installing a font requires elevated permission, which normal web application running under restricted account does not have – IronGeek Dec 17 '15 at 16:18
  • Is there some reason why you're trying to find a global solution (installing a font to the system font directory), rather than a local solution (e.g. using the font directly from TTF)? – Luaan Dec 17 '15 at 16:28
  • 1
    You don't need the space in `startInfo.Arguments`. – Lloyd Dec 17 '15 at 16:47

1 Answers1

1

I believe that you are running the program with a under-privileged user... the IIS user, by default is "Network Authority", and this account cannot perform changes in the windows directory... try running this with a admin account...

Leonardo
  • 10,737
  • 10
  • 62
  • 155