2015-10-06 72 views
1

我正在編寫一個簡單的程序來獲得像ffmpeg這樣的進程的所有屬性。我得到了預定義函數的大多數屬性,但我想知道我給vb.net中的ffmpeg的參數?如何獲得vb.net中ffmpeg進程的參數?

For Each prog As Process In Process.GetProcesses 
     If prog.ProcessName = "ffmpeg" Then 
      al.Add(prog.Id) 
     End If 
    Next 

For Each id In al 
    Dim p As Process = Process.GetProcessById(id) 
    listBox3.Items.Add(Process.GetProcessById(id).ProcessName) 
    ListBox3.Items.Add(p.BasePriority) 
    ListBox3.Items.Add(p.HandleCount) 
    ListBox3.Items.Add(p.Id) 
    ListBox3.Items.Add(p.MainWindowTitle) 
    ListBox3.Items.Add(p.MaxWorkingSet) 
    ListBox3.Items.Add(p.MinWorkingSet) 
    ListBox3.Items.Add(p.PriorityBoostEnabled) 
    ListBox3.Items.Add(p.PriorityClass) 
    ListBox3.Items.Add(p.PrivilegedProcessorTime) 
    ListBox3.Items.Add(p.ProcessName) 
    ListBox3.Items.Add(p.ProcessorAffinity) 
    ListBox3.Items.Add(p.StartTime) 
    ListBox3.Items.Add(p.TotalProcessorTime) 
    ListBox3.Items.Add(p.UserProcessorTime) 
    lastBox3.Items.Add(p.WaitForInputIdle) 
    ListBox3.Items.Add("========================") 
Next id 
+0

使用由Jesse Slicer提供的WMI嘗試[answer here](http://stackoverflow.com/a/2633674/2330053)。 –

+0

你能舉一個小例子 – TOM

回答

1

使用傑西切片機的代碼從here基地:

Public Class Form1 

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
     For Each proc As Process In Process.GetProcessesByName("ffmpeg") 
      Debug.Print("ID: " & proc.Id) 
      Debug.Print("Arguments: " & proc.GetCommandLine) 
      Debug.Print("------------------------------") 
     Next 
    End Sub 

End Class 

Public Module Extensions 

    <Runtime.CompilerServices.Extension()> 
    Public Function GetCommandLine(ByVal proc As Process) As String 
     ' Project --> Add Reference --> System.Management 
     Dim arguments As New System.Text.StringBuilder 
     Using searcher As New Management.ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " & proc.Id) 
      For Each arg In searcher.Get 
       arguments.Append(arg("CommandLine") & " ") 
      Next 
     End Using 
     Return arguments.ToString.Trim 
    End Function 

End Module 

請注意,您需要添加系統管理參考,並且我將該函數作爲Process類的擴展方法。