使用 vb.net 中的文件路径以编程方式终止应用程序
我想通过 vb.net 使用完整文件路径终止应用程序,但在进程下找不到它。我希望有一个简单的 Process.Stop(filepath),就像 Process.Start 一样,但没有这样的运气。
我怎样才能这样做呢?
I want to terminate an application using the full file path via vb.net, yet I could not find it under Process. I was hoping for an easy Process.Stop(filepath), like with Process.Start, but no such luck.
How can I do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须查看每个进程的“模块”属性,然后根据所需的路径检查文件名。
下面是一个示例:
VB.NET
C#
编辑:更新了代码以在字符串比较时考虑区分大小写。
You would have to look into each process' Modules property, and, in turn, check the filenames against your desired path.
Here's an example:
VB.NET
C#
EDIT: updated the code to take case sensitivity into account for string comparisons.
尝试
System.Diagnostics.Process.GetProcessesByName(nameOfExeFile).First().Kill()
这会忽略文件的路径。
try
System.Diagnostics.Process.GetProcessesByName(nameOfExeFile).First().Kill()
This ignores the path of the file.