Wednesday, August 4, 2010

Shortcut / delete items / EXE self-delete DIY


Each programming enthusiasts, and hope that their work accepted and loved for everyone, but most of our work is a simple EXE file copy, not only did not remove the program without installing, people think only process rather than product, Following my example and to share what Delphi program group shortcuts to create, add remove program group in the removal of items and procedures for self-delete function.
1. Following the establishment of procedures to introduce the first group of shortcut method:

Unit in the uses to add shlobj, activex, comobj, in the window add a button, and add the following code in their event:




procedure TForm1.Button1Click (Sender: TObject);
var sl: ishelllink;
pf: ipersistFile;
lnkName: Widestring;
app: string;
begin
olecheck (cocreateInstance (clsid_shellLink, nil, Clsctx_inproc_server, iShellLink, sl));
pf: = sl as IPersistFile;
app: = application.exename;
OleCheck (sl.SetPath (pchar (app )));// establish an effective link
LnkName: =''C: WINDOWSStart MenuProgramsredbird.lnk''; / / set the target file
pf.Save (PWideChar (lnkName), true); / / Save the file
end;
Of course, this code should be placed above the first run when the program code, but also the location of the program group or the desktop to the registry HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders best to the corresponding value in the subject. The operation of your registry on the registry by Delphi encapsulates the TRegistry to complete, this method is simple, in this respect will not go into, if you want to write a smaller program, or you are using VB programming, then may call the API. The following will be on the registry API functions of the direct call to tell you how to establish Add or Remove Programs item. Similarly, this code should be placed on the first run-time program execution.






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, / / Registry root key
''SoftwareMicrosoftWindowsCurrentVersionUninstallMyApp''/ / your program entries
, 0, nil, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, nil, IKey, @ IHand);




RegSetValueEx (Ikey,''DisplayName''
, 0, REG_SZ, Pchar (''remove me !'')// delete the characters displayed in the list
, 10); / / characters in length
RegSetValueEx (Ikey,''UninstallString'', 0
, REG_SZ, pchar (ParamStr (0) +''/ UNINSTALL''),// delete the command line call
4);
end. This code will process your name and full path "/ UNINSTALL" parameter write to the registry HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionUninstallMyApp, you can be in the Add or Remove Programs to see "Remove me!" project, and when you click on this item When your program through ParamStr (1) will receive "/ UNINSTALL" parameter, and thus calls for the identification code that can remove the program. Let us introduce the following procedures when you receive this parameter, without calling other programs and "self-delete" of the two methods.

One of them is received after this parameter dynamically create a batch file to delete files, the program generated within the installation process, such as shortcuts and delete files and registry values before exiting after the call this batch file will own you can delete, such as:




procedure TForm1.FormCreate (Sender: TObject);
var f: textfile; / / author does not recommend that you remove the code in FormCreate incident, the author believes that the possibility can not be deleted will appear.
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; on the treatment of simple text files, several times to explore the writer found a better second method is simple, direct call to the command shell to complete the deletion of work:




application.Terminate;
winexec (pchar (''command.com / c del''+ ParamStr (0)), SW_MINIMIZE); / / implementation of minimum deletion, or the moment will see the DOS window flashing
halt;





Recommended links:



Mov to avi converter



S first day of the prohibited advertising ban quiet Changing Faces "painless abortion" to "unwanted



Out of the ESB Mistakes: Ten Myths opened ESB



Evaluate Graphic



MY performance gone?



Interview with B & Q (China) Vice President, Human Resources Director Miss Hu Weiyan



News ABOUT Hobby



Reference Tools For You



blackberry video Format



Converter Mp4 To 3gp Free



Seattle interactive e-learning global Language laboratory



Revitalization of Road Reflection RFID



TAOBAO Alipay betrayal?



Audio Rippers And Converters Wizard



Flv to 3gp



A class with no class routing under the Matching principle route



How TO enhance the productivity of textile and garment factories?



No comments:

Post a Comment