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.
            Asked
            
        
        
            Active
            
        
            Viewed 1,079 times
        
    4
            
            
        - 
                    1What'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
 - 
                    3Please 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 Answers
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
 
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...
        Chris Sterling
        
- 99
 - 6