Forum posts for iexplore.exe

How to capture keystrokes of iexplore.exe only?

My goal is to capture keystrokes of the user when he is interacting with Internet Explorer (iexplore.exe).

This is my DLL code for a DLL called hook.dll.

#include <iostream>
#include <windows.h>

extern 'C' __declspec(dllexport)
LRESULT keyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode >= 0) {
std::cout << 'nCode: ' << nCode << '; wParam: ' << wParam
<<' (' << char(wParam) << '); scan code: '
<< ((lParam & 0xFF0000) >> 16)
<< '; transition state: ' << ((lParam & 0x80000000) >> 31)
<< std::endl;
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
std::cout << 'hinstDLL: ' << hinstDLL
<< '; fdwReason: ' << fdwReason
<< '; lpvReserved: ' << lpvReserved << std::endl;

return TRUE;
}


Here is the main program code for main.exe:

#include <iostream>
#include <windows.h>

int main(int argc, char **argv)
{
HMODULE dll = LoadLibrary('hook.dll');
if (dll == NULL) {
std::cerr << 'LoadLibrary error ' << GetLastError() << std::endl;
return 1;
}

HOOKPROC callback = (HOOKPROC) GetProcAddress(dll, 'keyboardHook');
if (callback == NULL) {
std::cerr << 'GetProcAddress error ' << GetLastError() << std::endl;
return 1;
}

HHOOK hook = SetWindowsHookEx(WH_KEYBOARD, callback, dll, NULL);
if (hook == NULL) {
std::cerr << 'SetWindowsHookEx error ' << GetLastError() << std::endl;
return 1;
}

MSG messages;
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
UnhookWindowsHookEx(hook);
}


I compile this project with these commands:

vcvars32.bat
cl /LD hook.cc /link user32.lib
cl main.cc /link user32.lib


When I execute the program, and press the keys A, B and C, I see the following output.

C:>main
hinstDLL: 10000000; fdwReason: 1; lpvReserved: 00000000
nCode: 0; wParam: 65 (A); scan code: 30; transition state: 0
nCode: 0; wParam: 65 (A); scan code: 30; transition state: 1
nCode: 0; wParam: 66 (B); scan code: 48; transition state: 0
nCode: 0; wParam: 66 (B); scan code: 48; transition state: 1
nCode: 0; wParam: 67 (C); scan code: 46; transition state: 0
nCode: 0; wParam: 67 (C); scan code: 46; transition state: 1


This is all good so far, but this program captures keystrokes made anywhere on the desktop. But I want to capture only those keystrokes that are made on Internet Explorer. I believe I need to modify the SetWindowsHookEx(WH_KEYBOARD, callback, dll, NULL); call in main program and pass the thread ID of the Internet Explorer as the fourth argument to this call. Could you please help me to solve this problem?

View complete forum thread with replies

Other posts related to iexplore.exe

See Related Forum Messages: Follow the Links Below to View Complete Thread

How can I find programatically where iexplore.exe is?
Strange ProcessorAffinity issue with IEXPLORE.exe
iexplore.exe process opens but I can&#39;t see it
Batch file to terminate all instances of IExplore.exe
Debugging SHDocVw.InternetExplorer.Quit not closing iexplore.exe process
Process.Start(&ldquo;IExplore.exe&rdquo;); &lt;&mdash; Is this reliable?
VS2010 and IE10 Attaching the Script debugger to process iexplore.exe failed
How to capture keystrokes of iexplore.exe only?
Process.Start(&ldquo;IEXPLORE.EXE&rdquo;) immediately fires the Exited event after launch.. why?
Unhandled exception at 0x75619617 (KernelBase.dll) in iexplore.exe
Process.Kill does not seem to work with iexplore.exe
invoke iexplore.exe in already launched instance using ShellExecuteEx
Run iexplore.exe invisibly
Attaching the Script debugger to process &#39;[XXXX] IEXPLORE.EXE&#39; on machine &#39;NAME&#39; failed
Can I pass the -f parameter to iexplore.exe when using Watir?

What is the carbon footprint of your coffee?

Is it low? Is it high? Can this things really kill the planet Earth? Maybe the answer will surprise you. Maybe not.