BeniBela online

The programming of joke programs

Actually you can't write hidden joke programs with functions of Delphi, but you can use functions of the Win API for joke programs. These functions you can also use in other languages. Beginners can use my component TCVirus which has implemented a lot of the functions.

Bases

It is important for such joke programs that a normal user can't find and stop them.
If you use TCVirus, the hiding of the program is simple, because you can use the methode HideFromTaskManager to remove its entry in the task manager and the methode Hide together with the Parameter (form1.)handle to hide it from the screen and from the task list. When you are using the Win-API this is more difficult: You can hide the program from the task manager if you call RegisterServiceProcess(GetCurrentprocessID,1), but at first you have to import this procedure. In Delphi you can do this with typing:
function RegisterServiceProcess(dwProcessId,dwType:Dword):DWord; stdcall; external 'KERNEL32.DLL'.
However the program doesn't start on newer Windows versions than WinME anymore after you have written this line. TCVirus doesn't have this problem because it loads the function dynamically. How this works you can read in Assarbad's DLL Tutorial.

Another possibility (which also works only on W9x) to "remove" the program from the task manager is to prevent the user from calling the task manager, by simulating a screen saver: SystemParametersInfo(SPI_SCREENSAVERRUNNING,1,0,0);
If you want to activate the keys, you can call:
SystemParametersInfo(SPI_SCREENSAVERRUNNING,0,0,0);
Achieving this effect on newer NT systems is much more difficult, for example you could rewrite the (Graphical Identification and Authentication DLL) or the keyboard driver.
But most of the users don't know the processes running on their system, so if you name your program like VeryImportantMouseDriver.exe, they will not stop them.

The hiding from the task list is much more simple: ShowWindow(application.handle,sw_hide). With Application.handle you get the handle of the main window of your application. After calling the procedure it will be hidden.

However there should be a way to stop the program (of course you could kill it with a process viewer like APIV, but then memory ressources could be lost).
TCVirus has a built in possibility, to stop the program, when the mouse arrives a special position. This Position can be set with the properties XMouseTest and YMouseTest.
The property MouseTestIntervall determines, how often the mouse position is checked. When the mouse arrives the point the event OnMousePos is called.
Of course you can write there something else than close. With the Win-API you get the mouse position over the function getMousePos.

You also can check the keyboard:
GetAsyncKeyState(number)
Instead of number you should insert the virtual key code of the key to check.

Jokefunctions

You can surprise the user with opening or closing the door of the cd drive.
TCVirus has the methodsopenCDTray and closeCDTray.
If you use the Win API, you have to use these commands:

This function is declared in mmsystem, so you have to include this unit.

Another effect is to draw on the screen. The functions of the Win API need for each access to the screen a graphic handle of it. One handle is stored in the property canvas.handle of TCVirus.
You have to create a new handle, if you don't use TCVirus. To create it call: createDc('DISPLAY',nil,nil,nil). After using it, you can (and have to) remove it with DeleteDc.


When you have a handle or TCVirus, you can mirror the screen:
TCVirus has easy methodes for this: Canvas.MirrorHorizontal and Canvas.Mirrorvertikal.

The Win-API is more complex:

Replace handle with the handle of the screen.


You can also draw circles, rectangles, ellipses or lines.
The features of TCVirus make it possible to paint on the screen like on any normal surface in Delphi. It has got a property canvas you can use to call the numerous graphic functions.
Because these functions are explained in the Delphi help file and in the (German) help of TCVirus, I don't repeat this descriptions here, and only name the way over the Win API which is very similar.
The functions rectangle and ellipse draw a rectangle or an ellipse. They want 5 parameters, the handle of the desktop, the coordinate of the left top point, and the coordinates of the right bottom point.
Lines can be created with MoveToEx and LineTo. At first you move the cursor with the function MoveToEx to the start position of the line. You need 4 parameters, handle, coordinates, null.
Then you can call LineTo to draw the line to the destination point.
TextOut(handle,XPos,YPos,text) draws a text on the screen.

If you want to change the color of the figures you can use these functions:
You can set the color of the border of the objects with: SelectObject(handle of the screen,CreatePen(PS_SOLID,1,color).
You get the handle of the old pen which you need to delete the new own with:DeleteObject(SelectObject(handle of the screen, handle of the old pen).
The determining of the fill color is similar: You create a brush with: CreateSolidBrush(color), instead of CreatePen.
But you only need these functions, when you are using the Win API. TCvirus has got the properties canvas.pen.color and canvas.brush.color which set the colors.

The Win API can also invert an area of the screen:
InvertRect(Handle of the screen,area).
You have to set instead of area a pointer on a record of the type TRect. You can create such a record object with: rect(left, top, right, bottom).

And the API can draw an image on the screen: DrawState(handleS, dss_normal nil, image,0,x, y, width, height, dst_bitmap);

. You should write instead ofhandleS the handle of the screen, instead of image the handle of the image (for example: image1.picture.bitmap.handle, if you use a TImage), instead of (x,y) the destination coordinates, and instead of (width, height) the size of the image.

You also can change the LEDs on the keyboard:
TCVirus has the methode SetKeyBoardLEDs(numlock, caps, scroll) for this purpose.
The parameter are boolean values. If you type true the LED is on, by false it is off. The order of the arguments is equal to the order of the keyboard.
The Win API need this way:
At first you create a variable with type pbKeyState(in Delphi = TKeyboardState).
Then you call GetKeyboardState with this variable to get the current keyboard status. You can now set the status of the LEDs with keyState[LED Code] := 0 or 1;<:
YOu should replace LED Code with the code of the LED (in the order of the key board:VK_NUMLOCK, VK_CAPITAL und VK_SCROLL).

Another very surprising effect is to hide the icons on the desktop.
At first you need the handle of the window containing the icons.
TCVirus returns such a handle, if you call GetIconDesktop. If you use the Win API you can write:
handle:=FindWindowEx(FindWindowEx(FindWindow('Progman', nil),0,'SHELLDLL_DefView',nil),0,'SysListView32',nil); (This means that the program searchs the handle of the windows "SysListView32" of windows "SHELLDLL_DefView" of the top level Windows "Progman", these names you can find out with programs like APIV.).
When you have the handle you can type to hide them:
EnableWindow(handle ,false);
SetWindowPos(handle,HWND_BOTTOM, 0, 0, 0, 0, SWP_HIDEWINDOW);

To show them again, write:
EnableWindow(handle ,false);
SetWindowPos(handle,HWND_BOTTOM, 0, 0, 1, 1, SWP_SHOWWINDOW);


You can also let windows call the program by each start of the computer, when you know the name and position of your program. (you get this information withParamStr(0)) Then you write this into a certain registry key:: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run or HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
The entry must be a string, and its value must be the name and position of the program.
Delphi has got registry methodes which make this really simple, more you can find in the Delphi help.
On a NT system you can't write into the "local lachine" key, when the user has no admistrator rights. But if you write in "local machine" the program is called independent of the user logged in.

Joke programs for download

Bildwackler (150 KB)

This joke program mirrors each second the screen vertically and horizontally. To stop the program press |Ctrl| + |SHIFT| + |A|.

HokusScherz(737 KB):

It creates a moving little magician telling a story in German, so you can't understand everything,, if you aren't able to understand this language. The magician is created with DrawState. Then it conjures the task list, then the task button and the TNA starts moving around. After this the whole screen is painted black, and the computer is turned off. After a reset the program is started again because it has written into the registry in the key: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
The written value is named LoadPower and has the content C:\LoadPower.exe.
If you don't know the registry and DOS, you shouldn't download this program because some computers don't start anymore and you have to delete the file C:\Loadpo~1.exe in DOS.

Joke programs from other people

Joke program of Andre Jochim (131 KB):

www.andre-jochim.de
This program is freeware and you are allowed to change it.
At the first start it copies itself into the Win-directory named sosystem.exe, creates the file C:\check.in, writes into the Registry, and shows an error message something hasn't worked.
You can delete it by removing the files
C:\windows\sosystem.exe and c:\check.in. and the value 'SoundMX-3G MasterSet' in
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run.

I don't take responsibility for any damages created by these programs by pure chance. These programs are given "as is" without any guarantee.

If you have written a joke program, please send it to me, if you want, that it is published here. Please send only programs documented like the ones above and which are no more risky than HokusScherz.


www.benibela.de/jokeprograms_en.html
Last change of the content of this page: 2009-12-26 00:01:19+0100
Last change of this page: 2014-08-23 22:37:13+0200
For G+ authorship:
Personal home page of