Reputation: 21
Im attempting to kill a process remotely by using pskill.
From the command line, pskill works great, but when trying the same command in C# Im getting an access denied error.
var startInfo = new ProcessStartInfo {
FileName = "pskill.exe",
Arguments = "-t \\" + _currentMachine +
" -u BobSmith -p Pass123 " + _currentService +
" /acceptEULA"
};
try {
using (Process exeProcess = Process.Start(startInfo)) {
exeProcess.WaitForExit();
}
} catch {
Console.WriteLine("Cannot forcibly kill process.");
}
I have even tried creating a .bat file which runs fine manually but I get the same error when trying to call the .bat from C#.
Im on an XP machine attempting to access a win 2003 server.
Upvotes: 1
Views: 5399
Reputation: 21
For the next guy...
pskill.exe needed to be run in Win2000 compatibility mode.
Upvotes: 1
Reputation: 2801
In C# characters in strings are escaped by default. The string you assign to Arguments contains two escape characters. I suspect that they are turned into a single back slash. Add an @
in front of the string definition to resolve this.
Arguments = @"-t \\" + _currentMachine +
In any case I would suggest adding code to write the whole command line out to a text file and check that it is as you need it. If the text file has a bat extension can you run it successfully?
Upvotes: 0
Reputation: 5463
I would double check your credentials. It is either that or your process is 'locked'.
Upvotes: 0