I am using paexec in my C# project and I am trying to avoid providing the password using the "-p" command line argument because while paexec is still running anyone using a utility such as Process Explorer from SysInternals could see the password in plaintext as part of the process command line arguments.
Here is my approach number one, including credentials with the ProcessStartInfo object:
Process p = new Process();
p.StartInfo.FileName = "paexec.exe";
p.StartInfo.Arguments = "\\\\remote_system remote_app.exe";
p.StartInfo.UseShellExecute = false;
string pw = "password";
System.Security.SecureString ss = new System.Security.SecureString();
for (int i = 0; i < pw.Length; i++)
{
ss.AppendChar(pw.ToCharArray()[i]);
}
p.StartInfo.Domain = "domain_name";
p.StartInfo.UserName = "administrator";
p.StartInfo.Password = ss;
p.Start();
p.WaitForExit();
With the above code I would get an access denied message.
Approach number two, redirect PaExec IO:
ProcessStartInfo psi = new ProcessStartInfo("paexec.exe", "\\\\remote_system -u administrator remote_app.exe");
psi.UseShellExecute = false;
psi.RedirectStandardInput = true;
Process p = Process.Start(psi);
StreamWriter inWriter = p.StandardInput;
inWriter.WriteLine("password_here");
p.WaitForExit();
Console.WriteLine(p.ExitCode);
In this case the paexec console window is just blank, and remote_app.exe doesn't get executed.
Has anyone ever able to accomplish this?