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.
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
精彩评论