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.
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.
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.
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).
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