Click here to Skip to main content
15,886,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello everyone i was wondering if anyone knew how i could close a program or textfile by its path so (C:\Users\brandon\Documents\NewTextDoc (2)) or (C:\Users\brandon\Documents\Hey.exe as an example can anyone help me out. Thanks.

What I have tried:

i havent really tried anything im just trying to have fun with programs and not sure where to start with this does anyone know what i could do?
Posted

1 solution

You can't - you need it's Process to access it.
Think about it: if I run two copies of the same program, which one should you close?

You can use Process.GetProcesses[^] to get all the currently running processes, then Process.Kill[^] to kill a specific process.
Each Process object has properties you may be able to use to identify thr one you want: Process Class (System.Diagnostics)[^] including the ProcessName and MainWindowTitle
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900