I just want to check if any desired application is already running or not
for eg suppose I have VLC or iTunes or any windows application then how can i figure it out by c# code if it is running or not.
string fileName = Path. GetFileName(path); // Get the precess that already running as per the exe file name. ' Pass your exe file path here.
The best place to start when monitoring apps is the Task Manager. Launch it from the Start menu or with the Ctrl+Shift+Esc keyboard shortcut. You'll land on the Processes screen. At the top of the table, you'll see a list of all the apps which are running on your desktop.
This should be pretty easy to find with a quick Google search, but here you go:
if (Process.GetProcessesByName("process_name").Length > 0)
{
// Is running
}
Replace process_name
with the name of the process you are looking for (i.e. vlc
).
Checking for Self-Process
As pointed out in the comments by @filimonic, if you want to check whether more than one instance of the application is running you can use > 1
in place of > 0
:
if (Process.GetProcessesByName("process_name").Length > 1)
{
// Is running
}
This works by checking that a maximum of 1 processes is currently running.
you can use either Process.GetProcessesByName
if you know the process name or Process.GetProcessesByID
if you know it's ID.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With