这个错错误在哪里?怎么搞都提示程序没有打开!我是新手,请指正!
'查找进程句柄的快照Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Integer, ByRef lProcessID As Integer) As Integer
'获得第一个进程的句柄
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Integer, ByRef uProcess As PROCESSENTRY32) As Integer
'获得下一个进程的句柄
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Integer, ByRef uProcess As PROCESSENTRY32) As Integer
'关闭打开的API句柄
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer
Private Const TH32CS_SNAPPROCESS = &H2
Private Const TH32CS_SNAPheaplist = &H1
Private Const TH32CS_SNAPthread = &H4
Private Const TH32CS_SNAPmodule = &H8
Private Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule
Private Structure PROCESSENTRY32
Dim dwSize As Integer
Dim cntUseage As Integer
Dim th32ProcessID As Integer
Dim th32DefaultHeapID As Integer
Dim th32ModuleID As Integer
Dim cntThreads As Integer
Dim th32ParentProcessID As Integer
Dim pcPriClassBase As Integer
Dim swFlags As Integer
Dim szExeFile As String
End Structure
Private Sub demo()
Dim MySnapHandle As Integer
Dim ProcessInfo As PROCESSENTRY32
MySnapHandle = CreateToolhelpSnapshot(TH32CS_SNAPall, 0)
ProcessInfo.dwSize = Strings.Len(ProcessInfo)
If ProcessFirst(MySnapHandle, ProcessInfo) <> 0 Then
Do
If Strings.Left(Strings.LCase(ProcessInfo.szExeFile), Strings.InStr(ProcessInfo.szExeFile, ".") + 3) = "notepad.exe" Then
'遍历进程,查找notepad.exe,找到后执行操作.......
MsgBox("写字本已打开")
Exit Do
End If
Loop While ProcessNext(MySnapHandle, ProcessInfo) <> 0
Else
MsgBox("写字本没有打开")
End If
CloseHandle(MySnapHandle)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
demo()
End Sub