Home > Net >  How do i close my program if a process is running?
How do i close my program if a process is running?

Time:10-12

I need to create a simple tool for to add to my C# program.

If "chrome.exe" is running then Me Close

how can I accomplish that in C ?

CodePudding user response:

You can use System("query process > file.txt"); and then use functions like fopen to opent file.txt and then load list of processes to an array and then make if statement and search for yourprocessname.exe - and when condition is positive exit() function to close the program.

CodePudding user response:

The C language has no knowledge of the concept of "process". In C , there is no standard way to query whether another process exists. Such query must be made through the API of the operating system. First step is to know what operating system the program will be run on. Second step is to read the documentation of that OS.

  • Related