Home > Software engineering >  Consult about check application path, use the hooks call wrong, normal use button
Consult about check application path, use the hooks call wrong, normal use button

Time:10-31

Consult everybody, I want to check run qq. Exe program of path, use the following procedure, but I use the keyboard HOOK to perform error, and it can be normal use button in the main window, and why, is there any way to solve, please expert advice,
For Each ename In GetObject (" winmgmts: \ \. \ root \ cimv2: win32_process "). The instances_ 'circulation process
If UCase (ename. Name)=UCase (" qq. Exe ") Then MsgBox ename. Executablepath 'search called qq. Exe process path
Next

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Form1. FRM
 Private Sub Form_Load () 
HHook=SetWindowsHookEx (WH_KEYBOARD_LL, AddressOf MyKBHook, App. The hInstance, 0)
If hHook=0 Then End 'registration failure returns 0 If the hook, or returns a handle to registration of hook

End Sub

Private Sub Form_Unload (Cancel As Integer)
UnhookWindowsHookEx hHook
End Sub
Private Sub Command1_Click ()
Dim ename As Object
For Each ename In GetObject (" winmgmts: \ \. \ root \ cimv2: win32_process "). The instances_ 'circulation process
If UCase (ename. Name)=UCase (" qq. Exe ") Then MsgBox ename. Executablepath 'search called qq. Exe process path
Next
End Sub

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Module1. Bas
 
Public hHook As Long 'used to store a handle to the hook

Declare the Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long

Declare the Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal LPFN As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Declare the Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam) As Long As Long

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any Source, As Any, ByVal Length As Long)
The Public As a Long

The Public Type EVENTMSG
VKey As Long
SKey As Long
Flag As Long
Time As Long
End Type

Public mymsg As EVENTMSG
Public Const WH_KEYBOARD_LL=13
Public Const WM_KEYDOWN=& amp; H100


Public Function MyKBHook (ByVal ncode As Long, ByVal wParam As Long, ByVal lParam) As Long As Long
Dim ename As Object
'these parameters have different meanings in different hooks, ncode here is the code type
If ncode=0 Then
If wParam=WM_KEYDOWN Then 'here indicated wParam keyboard events, specific key information stored in memory area the lParam pointer points to

'the memory data is copied to the mymsg lParam pointer points to the custom type
CopyMemory mymsg, ByVal lParam, Len (mymsg)

If wParam=WM_KEYDOWN Then
CopyMemory mymsg, ByVal lParam, Len (mymsg)
The Select Case mymsg. VKey
Press the TAB key Case vbKeyTab '
MsgBox "TAB"
For Each ename In GetObject (" winmgmts: \ \. \ root \ cimv2: win32_process "). The instances_ 'circulation process
If UCase (ename. Name)=UCase (" qq. Exe ") Then MsgBox ename. Executablepath 'search called qq. Exe process path
Next
End the Select
End the If
'Form1. Text1. Text=mymsg. SKey
End the If

End the If

'the message to the next hooks, if you want to lock the keyboard, only need to change this sentence to MyKBHook=1, said eat this news, it may not be able to keyboard input: -)
MyKBHook=CallNextHookEx (hHook, ncode wParam, lParam)

End the Function

CodePudding user response:

When your button event definitions change
Public Sub Command1_Click ()

And call the incident in your process, such as
Press the TAB key Case vbKeyTab '
Form1.Com mand1_Click
End the Select

CodePudding user response:

According to the above test, is still the same problems and automation error,
1. Click on the button operation, normal,

2. Press the Tab key, pop-up automation error, error is Command1_Click function,

CodePudding user response:

You don't use wmi, change the API to enumeration should be no problem, the low efficiency of wmi, and com/com + and internal service communication, so in ways may be more good
  • Related