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.
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:
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:
Instead of number you should insert the virtual key code of the key to check.
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:
- Open: mciSendString('Set cdaudio door open wait', nil, 0, 0);
- Close: mciSendString('Set cdaudio door closed wait', nil, 0, 0);
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:
- StretchBlt(handle, 0, 0, screen.width, screen.Height, handle, 0, screen.Height, screen.Width ,-screen.Height , SRCCOPY)
- StretchBlt(handle, 0, 0, screen.width, screen.Height, handle, screen.Width, 0, -screen.Width, screen.Height, SRCCOPY)
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:
SetWindowPos(handle,HWND_BOTTOM, 0, 0, 0, 0, SWP_HIDEWINDOW);
To show them again, write:
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
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 peoplewww.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
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.
For G+ authorship: