Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command2
Caption = "Command2"
Height = 495
Left = 2880
TabIndex = 2
Top = 1680
Width = 1215
End
Begin VB.ComboBox cmbProgram
Height = 315
Left = 1920
TabIndex = 1
Text = "Combo1"
Top = 360
Width = 1695
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 1080
TabIndex = 0
Top = 1680
Width = 1095
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private PIDs(1000) As Long
Private Sub RefreshProcessList()
Dim myProcess As PROCESSENTRY32
Dim mySnapshot As Long
cmbProgram.Clear
myProcess.dwSize = Len(myProcess)
mySnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
ProcessFirst mySnapshot, myProcess
cmbProgram.AddItem myProcess.szexeFile
PIDs(cmbProgram.ListCount - 1) = myProcess.th32ProcessID
While ProcessNext(mySnapshot, myProcess)
cmbProgram.AddItem myProcess.szexeFile
PIDs(cmbProgram.ListCount - 1) = myProcess.th32ProcessID
Wend
End Sub
Private Sub Command1_Click()
If pHandle > 0 Then
MsgBox "运行ing!", vbInformation, "OK"
Else
MsgBox "没有运行!", vbInformation, "警告"
End If
End Sub
Private Sub Command2_Click()
If InitProcess = True Then
MsgBox "打开进程", vbCritical, "test"
Else
MsgBox "不能打开进程", vbCritical, "test"
End If
End Sub
Private Sub Form_Load()
RefreshProcessList
End Sub
Attribute VB_Name = "Module1"
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
Declare Function GetLastError Lib "kernel32" () As Long
Public Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Public Const TH32CS_SNAPPROCESS As Long = 2&
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Public hProcess As Long
Attribute VB_Name = "Module2"
Public myHandle As Long
Function InitProcess() As Boolean
Dim pid As Long
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
If (hProcess = 0) Then
InitProcess = False
myHandle = 0
Else
InitProcess = True
myHandle = hProcess
End If
End Function