I'm facing on a crazy problem.
Using PsExec to run batch file remotely on a server. When I use the same command argument in the command line, all is fine.
Here is my batch file:
@ECHO OFF
ECHO %USER% >> "D:\Temp\TextFile.txt"
Here is my call to remote server:
var cmdFileOnRemoteServer = "D:\Temp\myBatchFile.cmd"
var cmdExe = @"C:\Exe\PsExec.exe";
var cmdArgs = string.Format(@"\\{0} -accepteula -u {1} -p {2} {3} {4}", serverName, userName, passWord, cmdFileOnRemoteServer, utilisateur;
proc = new Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.FileName = cmdExe;
proc.StartInfo.Arguments = cmdArgs;
proc.Start();
proc.WaitForExit();
var exitCode = proc.ExitCode;
exitCode = 0 in all time I'm using Asp.NET MVC app using application pool. I already use all option of PsExec. I grand all privilege on a remote server to an application pool which runs a website. Website installed on the server which uses PsExec.
Thanks & Regards
Camillelola
ASP.NET Developer