简体   繁体   中英

Link exe with application? c#

How to auto close an exe if my application close or forced to close. Is it possible to link exe file with my application? I can start exe inside win form but i want to start it outside the winform.

You'll want to use the Process class and get an instance using either GetProcessByName or GetProcessById . Then you can call Kill on the resulting object:

Process.GetProcessByName("process-name.exe").Kill();

This is a fairly nuclear option, though, so alternatively, you can instead try CloseMainWindow to attempt a more elegant close:

Process.GetProcessByName("process-name.exe").CloseMainWindow();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM