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:



Premier Download Managers



PMP candidates GENERALLY concerned



Compilation of various source - drives



convert Mp3 to aac



IDC how to charge only reasonable



Chang: The Heart of Love



Overcome medical "three long, one short" problem



E-Mail Clients Specialist



.m4v File



Yongchang combination of days thinking: eternal life To waste aluminum in the loop



Science - Screen Savers Directory



format Blackberry



Vertical Market Apps comments



CONVERT flv to mov



On the IMPLEMENTATION of financial knowledge in the use of



Agriculture: the first km and the last mile