I have an ASP.NET MVC4 website where I'm trying to execute a process on the server. The code is as follows:
ProcessStartInfo startInfo = new ProcessStartInfo()
{
FileName = ExeLocation,
Arguments = string.Format("\"{0}\"{1}", ScriptLocation, Arguments),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
WorkingDirectory = AppDir,
CreateNoWindow = true,
UserName = ExeUsername,
Password = ExePassword,
Domain = ExeDomain
};
using (Process process = Process.Start(startInfo))
{
using (StreamReader reader = process.StandardOutput)
{
output = reader.ReadToEnd();
}
using (StreamReader reader = process.StandardError)
{
error = reader.ReadToEnd();
}
process.WaitForExit();
if (process.ExitCode != 0)
{
throw new Exception(string.IsNullOrEmpty(output) ? error : output);
}
}
This works fine on my local machine in Visual Studio, but when I deployed to my server (W2K12) I get the following error:
Access is denied
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
I have the account referenced by ExeUsername
in both the Administrators and IIS_IUSRS groups on the server.
The application pool is running as a different account (hence the need to assign a specific account to run the process) which is also a member of Administrators and IIS_IUSRS on the server.
When I log into the server and run a command prompt as ExeUsername
, I am able to execute the process, so the issue must be related to executing from IIS.
What else could be blocking this access?
If you have domain be careful use domain\username for username
and also access to folder of deployment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With