vb는 프로세스의 시작 매개 변수를 얻었습니까?

Option Explicit Private Sub Form_Load () getProcessCommandLine "iexplore.exe"End Sub"는 모든 프로세스 이름이 proName인 상세한 목록을 얻을 수 있으며, 매개 변수는 반드시 완전하게 써야 합니다.Private Function getProcessCommandLine(ByVal proName As String) As String Dim objWMIService As Object Dim colProcessList As Object Dim objProcess As Object Dim objProType As Object Dim strResult As String Set objWMIService = GetObject("winmgmts:"& "{impersonationlevel=impersonate}!//./root/cimv2") Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name='"& proName & "'") If colProcessList.Count <> 0 Then For Each objProcess In colProcessList For Each objProType In objProcess.Properties_ If objProType.Name = "CommandLine"Then strResult = strResult & objProType.Value & vbCrLf Exit For End If Next Next End If If strResult <> ""Then getProcessCommandLine = strResult MsgBox strResult End If End Function
' , 
Private Function killProcessByPra(ByVal strProName$, ByVal strKeyPra$) As Boolean
    Dim objWMIService As Object
    Dim colProcessList As Object
    Dim objProcess As Object
    Dim objProType As Object
    Dim strResult As String
    Set objWMIService = GetObject("winmgmts:" & "{impersonationlevel=impersonate}!//./root/cimv2")
    Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name='" & strProName & "'")
     
    If colProcessList.Count <> 0 Then
        For Each objProcess In colProcessList
            For Each objProType In objProcess.Properties_
                If objProType.Name = "CommandLine" Then
                    If InStr(objProType.Value, strKeyPra) > 0 Then ' 
                        objProcess.Terminate
                        killProcessByPra = True
                    End If
                End If
            Next
        Next
    End If
End Function

' , true
Private Function isExistProcessByPra(ByVal strProName$, ByVal strKeyPra$) As Boolean
    Dim objWMIService As Object
    Dim colProcessList As Object
    Dim objProcess As Object
    Dim objProType As Object
    Dim strResult As String
    Set objWMIService = GetObject("winmgmts:" & "{impersonationlevel=impersonate}!//./root/cimv2")
    Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name='" & strProName & "'")
     
    If colProcessList.Count <> 0 Then
        For Each objProcess In colProcessList
            For Each objProType In objProcess.Properties_
                If objProType.Name = "CommandLine" Then
                    If InStr(objProType.Value, strKeyPra) > 0 Then ' true
                        isExistProcessByPra = True
                        Exit Function
                    End If
                End If
            Next
        Next
    End If
End Function

좋은 웹페이지 즐겨찾기