article

Hiding Processes

Email
Submitted on: 1/1/2015 12:44:00 PM
By: Exercia (from psc cd)  
Level: Intermediate
User Rating: By 10 Users
Compatibility: Delphi 5
Views: 3368
 
     The object of this short tutorial is to demonstrate how processes can be hidden from the windows, its taskbar, and its task manager. It also contains my code to hide from the task manager on 9x machines without crashing when run on NT, or XP.

 
				




[Introduction]

Normally I don't write tutorials or submit code. I'm no Jerome ;p But trying to find good resources for *truely* hiding programs from windows was such a task for me that I figured I would share what knowledge I've found. If you are interested in hiding your program from windows and the task list or just curious about the different ways you can do so, then this file is for you!


[Hiding From Task Manager #1]

The main way that everyone is telling you to do this is using code like this:

const
RSPSIMPLESERVICE = 1;
RSPUNREGISTERSERVICE = 0;
function RegisterServiceProcess (dwProcessID, dwType: DWord) : DWord;
stdcall; external 'KERNEL32.DLL';


RegisterServiceProcess(GetCurrentProcessID, RSPSIMPLESERVICE);

Simple enough, right? It seems so. Unfortunately when you try using this code under any OS except for a 9x machine, it will crash the entire program. It crashed mine even before I ever called the function! When I found this out I was frustrated because I wanted my bot to work universally on all OS's. Because of this, I finally found a way to make it work and wrote universally compatible code. If your code is meant only for Windows 9x machines, then there would be nothing wrong with using the previous code. If not, read on..


[Get Operating System]

In order to make the code that follows work, we must have a variable that will find the operating system. To do this, I have found (and slightly modified) the following code:

var
// Global OS vars
VersionInfo: TOSVersionInfo;
Platform: string;
MajorVersion,MinorVersion,Build: DWORD;

procedure GetOSVersion;
begin
VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo);
GetVersionEx(VersionInfo);

with VersionInfo do
begin
case dwPlatformId of
VER_PLATFORM_WIN32s: Platform := '3.1';
VER_PLATFORM_WIN32_WINDOWS : Platform := '98';
VER_PLATFORM_WIN32_NT:
begin
Case dwMajorVersion of
5 : Platform := '2000/NT';
else
Platform := 'NT';
end;
if dwBuildNumber > = 2500 then Platform := 'XP'
end;
end;

MajorVersion := dwMajorVersion;
MinorVersion := dwMinorVersion;
Build := dwBuildNumber;
end;
end;



[Hiding From Task Manager #2]

Now that we have a function to check the OS version we can add my universally compatible code to hide from 9x machines. First we need to add the type TReg before your implementation:

type
TReg = function (dwProcessID, dwType: DWord) : DWord;

Now for the code. In this example we will assume that the following code is put in a form's FormCreate event. Because that's most likely where you will want to put it:

var
RegisterServiceProcess: TReg;
begin

// Determine the operating system
GetOsVersion;

// Check to see if OS is 9x
if Platform = '98' then begin
Handle := LoadLibrary('KERNEL32.DLL');
if Handle <> 0 then begin
@RegisterServiceProcess := GetProcAddress(Handle, 'RegisterServiceProcess');
if @RegisterServiceProcess <> nil then
RegisterServiceProcess(GetCurrentProcessID, RSPSIMPLESERVICE);
end;
FreeLibrary(Handle);
end;
end;



[Hiding From NT]

This is a difficult task. NT boxes are not easily tricked. There is only one simple way that I've found to do this, and I believe it only works on NT 4.0. Go to your Project unit (IE. Project1) And find where it initializes and sets the application title. Replace it with this code:

Application.Initialize;
Application.Title:= '';

The version of NT that this works with (NT 4.0?) will not show your process in the manager because it displays processes by their titles, and your program is now running without one!


[Hiding from taskbar & windows]

The following is just a little piece of code I wrote to ensure that my form is unseen. It is commented so I will not explain it here:

procedure HideMe();
begin
// Make sure the form is out of sight
form1.Left := 99999;
form1.Top := 99999;

// Make form dissapear
form1.Visible := false;
Application.Minimize;

// Hide window entirely (dissapears from task bar!)
ShowWindow(Application.Handle, SW_HIDE);
SetWindowLong(Application.Handle, GWL_EXSTYLE,
GetWindowLong(Application.Handle, GWL_EXSTYLE)
or WS_EX_TOOLWINDOW );
end;



[Note]

Some code used in this tutorial was based on other's code. Thanks to those who wrote the original code.

[Conclusion]

Hopefully some of this has been helpful. I have no good HTML editor on this computer so this isn't a nice flashy tutorial. Good luck in your programming! I always am interested in hearing about new methods and techniques, so if you would like to share some feel free to drop me a line. Also, if you have a question with anything here or something else let me know and I'll do my best to help. Happy c0d1ng!
;)

-NaHeMiA-


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.