用API取得當前系統正在運行的進程,但是Process32First無效,請大家幫忙看看!!
Const MAX_PATH As Int32 = 260
Const TH32CS_SNAPPROCESS As Int32 = &H2
Const STANDARD_RIGHTS_REQUIRED As Int32 = &HF0000
Const SYNCHRONIZE As Int32 = &H100000
Const PROCESS_ALL_ACCESS As Int32 = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
<StructLayout(LayoutKind.Sequential)> _
Structure PROCESSENTRY32
Public dwSize As Int32
Public cntUsage As Int32
Public th32ProcessID As Int32
Public th32DefaultHeapID As Int32
Public th32ModuleID As Int32
Public cntThreads As Int32
Public th32ParentProcessID As Int32
Public pcPriClassBase As Int32
Public dwFlags As Int32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_PATH)> _
Public szExeFile As String
End Structure
Private Declare Function CreateToolhelp32Snapshot Lib "KERNEL32.dll" (ByVal dwFlags As Int32, ByVal th32ProcessID As Int32) As Int32
Declare Function Process32First Lib "KERNEL32.dll" (ByVal hSnapshot As Int32, ByRef lppe As PROCESSENTRY32) As Int32
Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Int32, ByVal bInheritHandle As Int32, ByVal dwProcessId As Int32) As Int32
Declare Function Process32Next Lib "KERNEL32.dll" (ByVal hSnapshot As Int32, ByRef lppe As PROCESSENTRY32) As Int32
Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Int32) As Int32
Private Sub GetProcessDetail()
Dim uSnapShot As Long '系统快照返回值
Dim uResult As Long '遍历进程返回值
Dim uProcess As PROCESSENTRY32 '定义进程结构变量
Dim meHandle As Long '进程句柄
uSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&) '建立系统快照
uProcess.dwSize = Len(uProcess) '初始化进程信息长度
If uSnapShot Then
uResult = Process32First(uSnapShot, uProcess) '取得第一个进程
Do While uResult
If InStr(Microsoft.VisualBasic.Left(uProcess.szExeFile, InStr(uProcess.szExeFile, Chr(0)) - 1), "SharpReader.exe") > 0 Then
meHandle = OpenProcess(PROCESS_ALL_ACCESS, True, uProcess.th32ProcessID)
MessageBox.Show(meHandle.ToString)
End If
uResult = Process32Next(uSnapShot, uProcess) '取得快照中的下一个进程
Loop
End If
CloseHandle(uSnapShot)
End Sub
--------------------编程问答--------------------
頂一下,
--------------------编程问答--------------------
process 不好用嘛.干嘛非用这个.
补充:.NET技术 , VB.NET