Invoking process under different user from ASP.NET web service

  • Thread starter Thread starter ljubop
  • Start date Start date
L

ljubop

Guest
Is there a way to run process as different user from ASP.NET rest API web application which runs as service.

If impersonation used before calling System.Diagnostic.Proccess.Start() it does not execute it under impersonated user.

However, if explicitly set username, password into ProcessInfo property that still does not execute – Access Denied:

if (!string.IsNullOrEmpty(userName))

{

process.StartInfo.UserName = userName;

Console.WriteLine(userName);

if (!string.IsNullOrEmpty(domain))

{

process.StartInfo.Domain = domain;

Console.WriteLine(domain);

}

}

if (!string.IsNullOrEmpty(password))

{

process.StartInfo.PasswordInClearText = password;

}

process.StartInfo.LoadUserProfile = false;

process.StartInfo.WorkingDirectory = @"C:\working";

process.StartInfo.CreateNoWindow = true;

process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

process.StartInfo.UseShellExecute = false;

process.StartInfo.RedirectStandardError = true;

process.StartInfo.RedirectStandardOutput = true;

process.StartInfo.LoadUserProfile = false;

var stdOutput = new StringBuilder();

process.OutputDataReceived += (sender, args) => stdOutput.Append(args.Data);

string stdError = null;

try

{

cmdExecmodle.OutputResult = " " + RuntimeInformation.OSDescription + "\r\n";

cmdExecmodle.OutputResult += " " + RuntimeInformation.ProcessArchitecture.ToString() + "\r\n";

cmdExecmodle.OutputResult += " " + WindowsIdentity.GetCurrent().Name + "\r\n";

process.Start();

process.BeginOutputReadLine();



if (waitForExit)

{

process.WaitForExit();

}

else

{

Thread.Sleep(500);

}

}

catch (Exception e)

{

throw new Exception("OS error while executing " + Format(filename, arguments) + ": " + e.Message, e);

}

If this is run from debug and/or IISExpress it works properly.

I've tried running service both under Local System and Administrator too. Also, I've been giving additional permissions to Administrator like:

  • Log on as a service Act as part of the operating system Adjust memory quotas for a process Replace a process level token

which did not helped.

Any ideas?

Continue reading...
 
Back
Top