Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get list of Process Names running, in VB.NET?

Tags:

process

vb.net

I am trying to find out if an instance of an application (not vb.net) is already running - because I will want to start it but I don't want to start it if it is already running. I have found a solution to check if a process is running:

Dim proc As Integer = Process.GetProcessesByName(ProcessName).GetUpperBound(0) + 1 

and return True if >=1 (or just the process number).

My problem is, this is a third-party application, and its process name is not just a name but it contains a version number (which I may not know at run time), and it also seems to add a *32 (so probably a *64 if it is installed in x64 ?).

I need to get a list of running processes, by name, and test if "processname" is a substring of the name. But I haven't been successful in getting a list of names, only process id's.

like image 593
Thalia Avatar asked Jun 15 '12 17:06

Thalia


People also ask

How do you check if a process is already running in VB net?

GetProcessesByName() does is indeed to see if there are any processes that run with a specified name, how many etc. This code will search for the process "processName.exe", so don't manually enter ".exe" in the process name.

What is a process in VB net?

With the VB.NET Process type, from System. Diagnostics, we launch processes directly inside programs. We can run an external EXE this way. Functions. Many new tasks become possible, with little extra complexity.


1 Answers

I need to get a list of running processes, by name, and test if "processname" is a substring of the name.

You could use:

Dim procExists as Boolean = Process.GetProcesses().Any(Function(p) p.Name.Contains(processName))

This will look through all of the processes, and set the procExists value to True if any process which contains processName exists in the currently executing processes. This should handle the existence of the unknown version number as well as the *32 that may occur if you're running on a 64bit OS (that's the WOW64 flag saying that it's a 32bit process running on a 64bit OS).

like image 192
Reed Copsey Avatar answered Oct 23 '22 17:10

Reed Copsey