I am attempting to execute a .bat
file on a remote machine (a server) that ends a process and kicks the user out of a database system. When executed on the server, the file works correctly and ends the process on the client machine.
However, when executed through C#, the command is entered into the command prompt and cannot execute. Here is the .bat
file;
psexec \\lp-100 msg * Hi Dan - your being removed!
pskill \\lp-100 sdcdatabase.vshost.exe
pause
The issue arises when executed in C#, this is the error message:
What this leads me to believe is that actually the .bat
file is not being executed on the server (that does have PsTools
installed), but instead the contents is being copied over and executed on the client machine instead.
Here is the code I am using to execute the .bat
file;
Process proc = null;
try
{
string batDir = string.Format(@"\\hqdb1\sdc_sqldb\pstools\");
proc = new Process();
proc.StartInfo.WorkingDirectory = batDir;
proc.StartInfo.FileName = "removeuser.bat";
proc.StartInfo.CreateNoWindow = false;
proc.Start();
proc.WaitForExit();
MessageBox.Show("Bat file executed !!");
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace.ToString());
}
Is this executing the .bat
file on the server, kicking the client off, or executing on the client and not finding PsTools
?