博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

如何获得一个进程的命令行参数?

Posted on 2009-11-24 16:42  随风飘零0  阅读(195)  评论(0编辑  收藏  举报

Option Explicit

Private Sub Form_Load()
    getProcessCommandLine
" notepad.exe "
End Sub

Private Sub getProcessCommandLine(ByVal proName As String )
   
Dim objWMIService As Object
   
Dim colProcessList As Object
   
Dim objProcess As Object
   
Dim objProType As Object
   
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
                    MsgBox objProType.Value
                   
Exit For
               
End If
           
Next
       
Next
   
End If
End Sub