Answer the question
In order to leave comments, you need to log in
How to check if a process with a specific name is running?
Is it possible to write such a code that will check for the presence of a running process, for example 123.exe, and if it is running, then the code will be executed? If possible, please tell me how to do it.
Answer the question
In order to leave comments, you need to log in
https://docs.microsoft.com/ru-ru/dotnet/api/system...
And there you are looking for a process with the desired name (ProcessName)
// Это всё можно запихнуть в таймер, например
var processName = "123.exe";
var processes = Process.GetProcesses().Where(p => p.ProcessName == processName);
foreach(var process in processes) {
Console.WriteLine(process.Id); // Ну или что там выполняем ещё
}
//Get a list of running processes
Process[] procList = Process.GetProcesses();
//The name of the process is needed
string name = "abc";
//Iterate through all the processes in the array
foreach(Process process in procList)
{
//If the process name matches the specified one, then do something
if(name == procList[i].ToString())
{
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question