4

I created a small basic key logger in C++. For some reason when I compile and run the program with the console displayed, it will record every key stroke I make in whatever program I am using such as a browser and store it in a text file. However when I make it so that it WON'T display a console window, it will not record anything and it's just a process in the background doing nothing. Here is the link to my code: http://pastebin.com/4wqQyLJ9 The function that is giving me trouble with hiding the console, is the Stealth() function. Any suggestions, tips or hints will be helpful.

Zombo
  • 1
  • 62
  • 391
  • 407
RandomGuy
  • 419
  • 4
  • 14
  • 1
    What's the point of `Stealth()` anyway? If you run as a console program you already have a console, so do just `ShowWindow(GetConsoleWindow(), SW_HIDE)`; if you run as a GUI... don't create the console at all. – Joker_vD Nov 07 '13 at 03:16
  • 3
    Please reduce your code to a [Short, Self Contained, Correct (Compilable), Example](http://sscce.org/) and include the code in your question, **not** a link to it. – Captain Obvlious Nov 07 '13 at 03:17

3 Answers3

2

Use this function , it works for me pretty well.

  ShowWindow(GetConsoleWindow(), SW_HIDE);
Coldsteel48
  • 3,482
  • 4
  • 26
  • 43
  • This also doesn't work for me. You may have to make a logger more sophisticated and respond to events from the OS. This would be the only reliable way to my knowledge. Dealing with Win32 or POSIX is a pain but it does work. – BlamKiwi Sep 24 '14 at 23:00
  • Change `int main()` to `int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)` instead. Then remove the `ShowWindow`.. This will make the console invisible. – Brandon Sep 26 '14 at 04:40
1

Instead of hiding the window after the program starts, I solved this by not having a window to begin with. Compile with -mwindows and a window is not created when the program starts.

Example

Zombo
  • 1
  • 62
  • 391
  • 407
0

I would consider a Windows Service for this kind of thing if you don't need UI. Also using GetAsyncKeyState can be more stealthy if required. This C++ source might be of use...

Windows Service Keylogger