如何在 VB.NET 中获取正在运行的进程名称列表? [英] How do I get list of Process Names running, in VB.NET?

查看:121
本文介绍了如何在 VB.NET 中获取正在运行的进程名称列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出应用程序(不是 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 

如果 >=1(或只是进程号),则返回 True.

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

我的问题是,这是一个第三方应用程序,它的进程名不仅仅是一个名字而是包含一个版本号(我可能在运行时不知道),而且它似乎还添加了一个*32(如果它安装在 x64 中,那么可能是 *64?).

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

我需要按名称获取正在运行的进程列表,并测试processname"是否是名称的子字符串.但是我没有成功获得名称列表,只有进程 ID.

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.

推荐答案

我需要按名称获取正在运行的进程列表,并测试processname"是否是名称的子字符串.

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

您可以使用:

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

这将查看所有进程,如果当前存在包含 processName 的任何进程,则将 procExists 值设置为 True执行过程.这应该处理未知版本号的存在以及如果您在 64 位操作系统上运行可能发生的 *32(即 WOW64 标志表示它是一个在 64 位上运行的 32 位进程操作系统).

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

这篇关于如何在 VB.NET 中获取正在运行的进程名称列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆