.NET ez 2012-11-11
Windows 7 含以上支援 taskkill 指令,Windows XP 只支援 tskill 指令,所以這邊偷懶利用 try cache,當 taskkill 無法使用時換成 tskill。
利用指令關閉 iexplore.exe:
while (Process.GetProcessesByName("iexplore").Length > 0) { Console.WriteLine("關閉瀏覽器"); try { Process P = new Process(); P.StartInfo.FileName = "taskkill"; P.StartInfo.Arguments = "/F /IM iexplore.exe"; P.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; P.StartInfo.CreateNoWindow = true; P.Start(); P.WaitForExit(); } catch { Process P = new Process(); P.StartInfo.FileName = "tskill"; P.StartInfo.Arguments = "iexplore.exe /A /V"; P.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; P.StartInfo.CreateNoWindow = true; P.Start(); P.WaitForExit(); } }
標籤: .NET
本文章網址:
https://www.ez2o.com/Blog/Post/csharp-Kill-Process-taskkill-tskill
https://www.ez2o.com/Blog/Post/299
https://www.ez2o.com/Blog/Post/csharp-Kill-Process-taskkill-tskill
https://www.ez2o.com/Blog/Post/299