I have two physical machine. The first machine want to execute a bat file on the second machine. I create a share location on the second server and tried to run it from the first machine and it does not work. The bat file can run on the local machine properly.
This is an example of code inside the bat file. It is just a bat to create file.
echo. 2>EmptyFile.txt
This is the code that I use to execute bat file.
private static void ExecuteBatFile()
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
System.Security.SecureString ssPassword = new System.Security.SecureString();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = @"\\my_remote_server\my_bat.bat";
proc.StartInfo.Domain = "my_domain";
proc.StartInfo.UserName = "my_username";
Console.Write("Enter your password: ");
string password = Console.ReadLine();
for (int x = 0; x < password.Length; x++)
{
ssPassword.AppendChar(password[x]);
}
proc.StartInfo.Password = ssPassword;
proc.Start();
}
I want to know how can I run bat file on remote server?
You can execute commands on remote machines using PsExec. I use it to execute batch files and pass parameters to them.