我如何知道将在vb.net中运行的进程的名称 [英] How do I know the name of the process that will be run in vb.net

查看:372
本文介绍了我如何知道将在vb.net中运行的进程的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何知道将在vb.net中运行的进程的名称



示例:运行Firefox,我希望我的节目中写有一条消息操作名称filefox.exe

How do I know the name of the process that will be run in vb.net

Example: run Firefox, I want my show a message written in the name of the operation "filefox.exe"

推荐答案

您可能(或可能不)获得您想要的名称 - 这取决于您启动的过程。

You may (or may not) be able to get the name you want - it depends on what process you start.
Process p = new Process();
p.StartInfo.FileName = @"D:\Temp\MyText.txt";
p.Start();
Console.WriteLine(p.ProcessName);

几乎肯定会给你进程名称Notepad(或者在我的情况下为PsPad) - 但是 它可能会抛出如果您打开(例如)HTML文件,则会出现无效操作异常。在我的系统上,这将打开Chrome,但由于Chrome会将请求发送到已经运行的实例并立即终止进程以便不生成新窗口它不起作用(因为进程ID不再运行) 。



不过,它可能就是你想要的,而且它几乎是获得它的唯一途径......

Will almost certainly give you the process name "Notepad" (or in my case "PsPad") - but it may throw an "invalid operation" exception if you open (for example) an HTML file. On my system, that will open with Chrome, but since Chrome throws the request to an already running instance and terminates the process immediately so as not to generate a new window it doesn''t work (because the Process ID is no longer running).

Still, it might be what you want, and it''s pretty much the only way to get it...


这篇关于我如何知道将在vb.net中运行的进程的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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