.NET ez 2014-10-02
利用Windows內建的taskkill及tskill指令關閉程式,只需將軟體名稱帶入function即可。
例如
Taskkill("notepad.exe");
或
Taskkill("notepad*");
/// <summary> /// 關閉軟體 /// </summary> /// <param name="ProcessName"></param> private void Taskkill(string ProcessName) { try { using (Process P = new Process()) { P.StartInfo = new ProcessStartInfo() { FileName = "taskkill", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, Arguments = "/F /IM \"" + ProcessName + "\"" }; P.Start(); P.WaitForExit(60000); } } catch { using (Process P = new Process()) { P.StartInfo = new ProcessStartInfo() { FileName = "tskill", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, Arguments = "\"" + ProcessName + "\" /A /V" }; P.Start(); P.WaitForExit(60000); } } }
標籤: .NET
本文章網址:
https://www.ez2o.com/Blog/Post/csharp-Kill-Process-taskkill-tskill-Function
https://www.ez2o.com/Blog/Post/463
https://www.ez2o.com/Blog/Post/csharp-Kill-Process-taskkill-tskill-Function
https://www.ez2o.com/Blog/Post/463