如何在vb.net中获取ffmpeg进程的参数?

时间:2015-10-06 14:08:30

标签: vb.net ffmpeg

我正在编写一个简单的程序来获取像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

2 个答案:

答案 0 :(得分:1)

使用Jesse Slicer的代码作为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

请注意,您需要添加System.Management引用,并使该函数成为Process类的扩展方法。

答案 1 :(得分:-1)

ffmpeg是开源的,所以它可能会有用: https://ffmpeg.org/documentation.html