Question

Is there a way to kill a batch process which is not started from C# code to kill from c# code. i.e. I have start.bat which is running and i want to kill it when a WPF app starts. Is this possible?? The WPF shall kill only start.at and not other batch running.

Was it helpful?

Solution 2

From powershell I find the PID of Start.bat like this.

(gwmi win32_process | where {$_.commandline -match "START.BAT"} | select processID).processID

Invoke powershell from C# or just contact WMI directly, easy to find if you look at Win32_Process commandline and processID properties.

OTHER TIPS

 int processID = ... 
 // you also can use    Process.GetProcessesByName(....) to find the proicessID - or the batch process

 //Later when you need to kill the process...
 Process pToKill = Process.GetProcessById(processID);
 pToKill.Kill();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top