WMI和获取VB.net中运行进程的CommandLine

发布于 2024-09-12 05:17:38 字数 260 浏览 4 评论 0原文

这是我想在 VB.NET 程序中使用的命令行。查找正在运行的进程“mpc-hc.exe”并获取正在运行的进程的命令行

wmic process where name='mpc-hc.exe' get CommandLine

我想将该命令的输出检索到字符串中。我知道它可以在 VB.NET 程序中本地完成,并且我已经研究了它是如何完成的。但是,我无法让代码执行上面命令行中的操作。

关于我应该如何实施这个有什么建议吗?谢谢。

This is the command line I want to use inside my VB.NET program. Look for the running process "mpc-hc.exe" and get the commandline of the running process

wmic process where name='mpc-hc.exe' get CommandLine

I want to retrieve the output from that command into a string. I know that it could be done natively in a VB.NET program and I have looked at how it was done. However, I cannot get the code to perform what it did in the commandline I have above.

Any suggestions on how should I implement this? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独享拥抱 2024-09-19 05:17:38

wmicWindows Management Instrumentation (WMI) API 的命令行包装器。在 .NET Framework 中,System.Management 命名空间提供对此 API 的访问。

下面是与命令行等效的 Visual Basic .NET。此代码查询 Win32_Process 类实例对应于 mpc-hc.exe 并读取其 CommandLine 属性:

Imports System.Management
...

Dim searcher As New ManagementObjectSearcher( _
  "SELECT * FROM Win32_Process WHERE Name='mpc-hc.exe'")

For Each process As ManagementObject in searcher.Get()
  Console.WriteLine(process("CommandLine"))
Next

wmic is a command-line wrapper for Windows Management Instrumentation (WMI) API. In .NET Framework, the System.Management namespace provides access to this API.

The Visual Basic .NET equivalent of your command line is below. This code queries the Win32_Process class instances corresponding to mpc-hc.exe and reads their CommandLine property:

Imports System.Management
...

Dim searcher As New ManagementObjectSearcher( _
  "SELECT * FROM Win32_Process WHERE Name='mpc-hc.exe'")

For Each process As ManagementObject in searcher.Get()
  Console.WriteLine(process("CommandLine"))
Next
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文