I'm try trying to launch remote command via psexec tool, it is running successfully in command prompt. However in c#, I get the following output error:
Access is denied
. here is my command:
psexec \servername -u xxxxxxx -p xxxxxxxxxx -h -w "E:\" cmd /C "(dir)" ^> file.txt
here is my c# source:
ProcessStartInfo PSI = new ProcessStartInfo();
PSI.FileName = "cmd.exe";
PSI.RedirectStandardInput = true;
PSI.RedirectStandardOutput = true;
PSI.RedirectStandardError = true;
PSI.UseShellExecute = false;
PSI.CreateNoWindow = true;
PSI.WindowStyle = ProcessWindowStyle.Hidden;
PSI.Arguments = "psexec " + @"\\servername -u xxxxxx -p xxxxxxxxx -h -w "+"\"E:\\\\\" "+"cmd /C " +"\""+"(dir)"+ "\" " +"^> file.txt" ;
p.Start();
p.WaitForExit();
output = p.StandardOutput.ReadToEnd().ToString();
error = p.StandardError.ReadToEnd().ToString();