Program ShortcutProgram DeleteEXE Self Delete DIY

zhaozj2021-02-17  49

Author: Firebird

Redbirdli@hotmail.com

Every programming enthusiast, I hope that my work can accept and love everyone, but most of our works is a copy of an EXE file. No need to install and do not delete the program, which makes people feel just the program, not the product. Here I use Delphi as an example and everyone to communicate the program shortcut, add the delete items in the deletion program group and the self-deletion of the program.

1. Let's first introduce the method of establishing a shortcut:

Add Shlobj, ActiveX, COMOBJ in the USES unit, add a button to the window and add the following code to its event:

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);

Var Sl: ishelllink;

PF: IPERSISTFILE;

LNKNAME: WIDESTRING;

App: String;

Begin

OLECHECK (CLSID_SHELLINK, NIL, CLSCTX_INPROC_SERVER, ISHELLLINK, SL);

PF: = SL as ipersistfile;

App: = Application.exename;

Olecheck (sl.setpath (Pchar (APP))); // Establish a valid link

LNKNAME: = 'c: / windows / start menu / programs / redbird.lnk'; // Set the target file

Pf.save (PWIDECHAR (LNKNAME), TRUE); // Save File

END;

Of course, the above code should be placed in the code segment for the first time of the program, and the location of the program group or the desktop is best necessary to register HKEY_CURRENT_USER / SOFTWARE / Microsoft / Windows / CurrentVersion / Explorer / Shell Folders. The value is accurate. Your operation of the registry can be done by Delphi's Tregistry encapsulated by the registry. This method is relatively simple, and there is no further details. If you want to write a smaller program or you are programming with VB, then To call the API. The following authors will introduce you to the project to establish a delete program with direct calls to the registry API function. Similarly, this code should also be executed when the program is first run.

PROGRAM Project1;

Uses

WINDOWS;

{$ R * .res}

Type

TregKeyInfo = Record

Numsubkeys: integer;

MaxSubKeylen: Integer;

Numvalues: integer;

MaxValuelen: Integer;

MaxDatalen: Integer;

Filetime: tfiletime;

END;

Var ihand: integer;

IKEY: HKEY;

Regs: TregKeyInfo;

Begin

RegcreateKeyex (HKEY_LOCAL_MACHINE, // Register Table Root "

'Software / Microsoft / Windows / CurrentVersion / Uninstall / MyApp' // Your Program Item

, 0, nil, reg_option_non_volatile, key_all_access, nil, iKey, @ihand;

RegSetValueex (iKey, 'DisplayName "

, 0. REG_SZ, PCHAR ('Delete I!') // Delete the characters displayed in the list

, 10); // Character length

RegSetValueex (iKey, 'Uninstallstring', 0

, REG_SZ, PCHAR (Paramstr (0) '/ Uninstall'), // Deletes the call line 4);

End.

This section writes your program full path name and "/ uninstall" parameter to the registry hkey_local_machine / software / uninstall / myApp, you can see "Delete me!" Project, and when you click this project, your program will receive the "/ uninstall" parameters through Paramstr (1), and call the code to delete the program for the ID. Let's introduce two methods that "self-delete" without calling other programs when you receive this parameter.

One of them is to dynamically establish a batch file that delete files after receiving this parameter, call this batch file before the program is deleted after the program is deleted after the program is deleted after the program is deleted. Delete, such as:

Procedure TFORM1.FormCreate (Sender: TOBJECT);

VAR f: textfile; // The author does not recommend that you delete the code in the FormCreate event, the author thinks that the possibility that will not be deleted.

Begin

Assignfile (f, 'temp.bat');

Rewrite (f);

Writeln (f, 'del' paramstr (0));

Writeln (f, 'del temp.bat');

Closefile (f);

Application.Terminate;

Winexec ('Temp.Bat', SW_HIDE);

Halt;

END;

The handling of text files is relatively simple, several exploits, the author has found a better second method, simple and easy, directly call the command shell to complete the deletion:

Application.Terminate;

Winexec (Pchar ('Command.com / C Del' paramstr (0)), SW_MINIMIZE); / / Minimizes Performing Delete Action, otherwise you will see the moment of the DOS window flashing

Halt;

Ok, there is a three-point decoration above, your program should be like a product, as for the content of the program, you have to be full.

Author: Firebird

Redbirdli@hotmail.com in 2000

Take a collection class overview .NET Collectes and related technologies via C #

Establish communication and data exchange servers with Delphi - TRANSCEIVER technology (on)

Establish communication and data exchange servers with Delphi - TRANSCEIVER technology (below)

Old Things: Program Shortcut / Program Delete / EXE Self Delete DIY

Old things: childhood programming algorithm

转载请注明原文地址:https://www.9cbs.com/read-30352.html

New Post(0)