http://blog.csdn.net/cw198624/archive/2009/02/19/3911759.aspx
添加一个ListBox和一个按钮
Option Explicit Private Declare Function CloseHandle Lib "kernel32" (ByVal Handle As Long) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long,ByVal bInheritHandle As Long,ByVal dwProcessId As Long) As Long Private Declare Function EnumProcesses Lib "psapi" (ByRef lpidProcess As Long,ByVal cb As Long,ByRef cbNeeded As Long) As Long Private Declare Function EnumProcessModules Lib "psapi" (ByVal hProcess As Long,ByRef lphModule As Long,ByRef cbNeeded As Long) As Long Private Declare Function GetModuleFileNameExA Lib "psapi" (ByVal hProcess As Long,ByVal hModule As Long,ByVal ModuleName As String,ByVal nSize As Long) As Long '上为函数声明,在此程序中EnumProcessModules为非必要,枚举进程路径,并不需要去枚举进程的模块。 Dim cbNeeded As Long,cbNeeded2 As Long,ProcessIDs(1 To 255) As Long Dim lRet As Long,ModuleName As String,hProcess As Long Const PROCESS_QUERY_INFORMATION = &H400 Const PROCESS_VM_READ = &H10 Dim DeskW As Long,DeskH As Long Private Sub Command1_Click() Dim ProcessCount As Long,I As Long List1.Clear Call EnumProcesses(ProcessIDs(1),256,cbNeeded) '返回进程PID数组和进程数组大小 ProcessCount = cbNeeded / 4 '计算出进程数 For I = 1 To ProcessCount hProcess = OpenProcess(&H400 Or &H10,False,ProcessIDs(I)) If hProcess <> 0 Then ModuleName = Space(255) '为模块名分配空间,这很重要 '模块句柄指针为零默认获取进程名,无需枚举进程模块 lRet = GetModuleFileNameExA(hProcess,ModuleName,255) List1.AddItem ProcessIDs(I) & Chr(9) & ModuleName '将进程PID和路径添加到列表框 End If lRet = CloseHandle(hProcess) '关掉进程句柄 Next End Sub
2010-02-23
http://www.docin.com/p-1549182.html