Chiêu thức lập trình VB 6.0
Liệt kê tất cả các Process đang hoạt động trong máy tính
Xuất xứ :
www.pscode.com
Binh khí sử dụng :
- 1 ListBox mang tên List
- 1 Module
Đoạn mã :
‘Trong Module :
'============================================
'Author: Joe Wong (Come from China)
'ICQ NO:7601450
'PLS VOTE FOR ME AND GIVE ME COMMENTS,thanks!
'==========================================
Public Declare Function CreateToolhelpSnapshot Lib "kernel32" _
Alias "CreateToolhelp32Snapshot" ( _
ByVal lFlags As Long, _
ByVal lProcessID As Long) As Long
Public Declare Function ProcessFirst Lib "kernel32" _
Alias "Process32First" ( _
ByVal hSnapShot As Long, _
uProcess As PROCESSENTRY32) As Long
Public Declare Function ProcessNext Lib "kernel32" _
Alias "Process32Next" ( _
ByVal hSnapShot As Long, _
uProcess As PROCESSENTRY32) As Long
Public Declare Function TerminateProcess Lib "kernel32" ( _
ByVal hProcess As Long, _
ByVal uExitCode As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" ( _
ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As
Long
Public Const TH32CS_SNAPPROCESS = &H2
Public Const TH32CS_SNAPheaplist = &H1
Public Const TH32CS_SNAPthread = &H4
Public Const TH32CS_SNAPmodule = &H8
Public Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist +
TH32CS_SNAPthread + _
TH32CS_SNAPmodule
Public Const MAX_PATH As Integer = 260
'define PROCESSENTRY32 structure
Public Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
‘Trong Form :
Private Sub TienHanh()
Tác giả : Lê Nguyên Dũng lớp 12C
1
trường THPT Đăk Nông Trang 1
Chiêu thức lập trình VB 6.0
Dim i
Dim theloop As Long
Dim proc As PROCESSENTRY32
Dim snap As Long
Dim exename As String
l.Clear
snap = CreateToolhelpSnapshot(TH32CS_SNAPall, 0) 'get snapshot handle
proc.dwSize = Len(proc)
theloop = ProcessFirst(snap, proc) 'first process and return value
i = 0
While theloop <> 0 'next process
exename = proc.szExeFile
list.AddItem exename 'add process name to listview
i = i + 1
theloop = ProcessNext(snap, proc)
Wend
CloseHandle snap 'close snapshot handle
End Sub
Tác giả : Lê Nguyên Dũng lớp 12C
1
trường THPT Đăk Nông Trang 2