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.
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...
Related
I am calling an exe program, when invoked requires inputfile.txt and its generates outputfile.txt in same folder. exe is working fine.
Now I want to convert same thing in web application but there I am getting issues.
Code I am using is as below
// Prepare the process to run
ProcessStartInfo start = new ProcessStartInfo();
// Enter in the command line arguments, everything you would enter after the executable name itself
start.Arguments = #"C:\Program Files\AET_Calculator\application\InputFile.txt"; ;
// Enter the executable to run, including the complete path
start.FileName = #"C:\Program Files\AET_Calculator\application\AET_Calculator.exe";
// Do you want to show a console window?
start.WindowStyle = ProcessWindowStyle.Hidden;
start.Verb = "runas";
start.UseShellExecute = true;
int exitCode;
// Run the external process & wait for it to finish
using (Process proc = Process.Start(start))
{
proc.WaitForExit();
// Retrieve the app's exit code
exitCode = proc.ExitCode;
}
Its throwing error. How can I call exe from web application passing input txt file
Here is error I am getting :
You need to grant execute access on the .exe file to the user in IIS is going to use to access the file, most of the time app pool identity or in IIS the IIS_WPG user.
I know this question was asked before over and over, but I couldn´t find a solution that worked for me.
my application needs to do some modification in the program files folders. It starts as a regular user. I found out that adding the app.manifest helps. So here´s part of my code:
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "cmd.exe";
info.Arguments = #"/c echo abc > ""%programfiles(x86)%\testfile.txt"""
info.CreateNoWindow = true;
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.WorkingDirectory = #"C:\Temp";
Process proc = new Process();
proc.StartInfo = info;
proc.Start();
Console.WriteLine(proc.StandardOutput.ReadToEnd());
Console.WriteLine(proc.StandardError.ReadToEnd());
proc.WaitForExit();
In my app.manifest this is what is relevant:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
If the user executing the application is a regular user, a UAC prompt will pop up requesting username and password (because of the manifest). Now, if I start the application with an admin user (using psexec for example)...
psexec.exe -u Username -p Password cmd /c myapp.exe
... I thought it would run like a charm, but instead it pops up a slightly different message asking me to confirm that I want the program to run (without fields for username and password). If I say yes, it runs fine.
What I want is that it runs with admin privileges, without any prompt, and without disabling UAC on registry for example. Is that even possible?
I am struggling in a issue related to windows services.
In my project , I want to change the sql service 'LOG ON AS' Local System using c# code.
You can do it in C# this way:
var process = new System.Diagnostics.Process();
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments= "/c sc.exe config \"mssql$sqlexpress\" obj= \"localsystem\" password= \"\"";
process.Start();
Note:
Pay attention to space after obj= and password=
isntead of mssql$sqlexpress, use your service name.
you may need run as administrator.
If you open the command prompt and run this command, your service account will change to local system account:sc.exe config "mssql$sqlexpress" obj= "localsystem" password= ""
I am trying to run a jar in C# by running this code:
System.Diagnostics.ProcessStartInfo processInfo = new System.Diagnostics.ProcessStartInfo(pathForjre+"java.exe", "-jar "+jar+" "+argsforjar);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = processInfo;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = false;
string out = "";
proc.Start();
proc.WaitForExit();
while (!proc.StandardOutput.EndOfStream)
out += proc.StandardOutput.ReadLine();
proc.Close();
return out;
When the jar runs I get an access denied exception with the path the jar is trying to write the log file to. I can manually run the jar from the command line and the log file writes no problem. How do I give the process permission to do things like write a file?
ASP.NET apps by default don't impersonate the identity of the user that is hitting the site. Typically then run as the local Network Service account unless you specifically have the process run under a different identity (you can determine the identity it's using by looking at Environment.UserName).
You can either set up the site (or use impersonation) to run under an identity that has permission to write to that location, or give write permision to the account that it's currently using.
Setting the working directory of the process resolved the issue.
proc.StartInfo.WorkingDirectory = path;
I have the below code in ASP.NET C# and it work fine in local system + production machine when i tested in debug mode. but it doesn't work when i uploading to IIS.
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = Server.MapPath(filePath);
startInfo.Verb = "print";
startInfo.Arguments = "Printer Name";
Process proc = new Process();
proc.StartInfo = startInfo;
proc.Start();
proc.WaitForExit(5000);
if (proc.HasExited == false)
{
proc.Kill();
}
Things i tried.
Control panel > Admin Services > Services > IIS Admin Service > Log on Tab > check to interact with desktop. Reset IIS Admin and IIS.
Printer Properties > Security > Grand ASPNET, NETWORK SERVICE, EVERYONE to full access.
Tried to set another printer as Default Printer. Reinstall / Add Printer.
I tried all the above with no success. finally i tried below in my machine.config.
WINNT>Microsoft.NET>Framework>v2.52something>Config> machine.config
I replaced this
processModel autoConfig="true"
with this
processModel userName="SYSTEM" password="AutoGenerate"
and i am getting this message
"Before you can perform print-related tasks you need to install a
printer"
i am using acrobat 7 and i can print the test page from printer itself and from acrobat software.
you can use Verb if acrobat is installed on you machine. and pass printer name as arguments
var fileName = #"c:\pdf\file.pdf";
var startInfo = new ProcessStartInfo(fileName);
string verbToUse = "PrintTo";
startInfo.Verb = verbToUse;
startInfo.Arguments = "PrinterName";
Process p = Process.Start(startInfo);
The issue may be that IIS runs under a different user that has less permissions than a typical User. See System.Diagnostics.Process.Start not work from an IIS
I fixed it on my server by changing the ProcessModel Identity to a user that has permissions. Probably a workaround and bad practice, but it worked. {Application Pool} -> Advanced Settings -> Identity -> Custom Account (Also toggle Load User Profile to true)