I have an exe which I can run in console like below
util.exe argument1
I need to invoke this from a CSharp application which I can do like below
private string Command(string arg)
{
var p = new Process
{
StartInfo =
{
FileName = "util.exe",
Arguments = arg,
RedirectStandardOutput = true,
RedirectStandardInput = true,
CreateNoWindow = true,
UseShellExecute = false
}
};
var stdOutput = new StringBuilder();
p.OutputDataReceived += (sender, args) => stdOutput.AppendLine(args.Data);
p.Start();
p.BeginOutputReadLine();
p.WaitForExit();
return stdOutput.ToString();
}
var result = Command(argument1) //call
However there is an issue. util.exe authenticates user using the Windows logged in credentials. In the application I need to execute the commands as a different user(Like below)
util.exe login funcationaluser fuucntioanluserpwd
util.exe argument1
What is the right way for doing this? Can I reuse the process?
Edit: Please note the username and password is specific to util.exe , not a system username/password