XP after Windows version Delphi Operation Registry Method

Source: Internet
Author: User

The program at hand needs to modify the registry so that the current program becomes the default open program in a format and associates the icon; Vista requires administrator privileges to operate the registry, which is cumbersome, so try the following.

Unit Unit1; Interface uses Winapi.windows, Winapi.messages, System.sysutils, System.variants, system.classes, Vcl.graphics, Vcl.
Controls, Vcl.forms, Vcl.dialogs, Vcl.stdctrls;
    Type TFORM1 = Class (Tform) Memo1:tmemo;
    Button1:tbutton;
    Procedure Formcreate (Sender:tobject);
  Procedure Button1Click (Sender:tobject);

Private {Private declarations} public {public declarations} end;

var Form1:tform1; Implementation {$R *.DFM} uses System.ioutils, Winapi.shellapi, winapi.shlobj;
RegApp function to use the function of the associated default program procedure RegApp (const Aext, aappname, aapppath:string);                    Const NREGFMT = ' Windows Registry Editor Version 5.00 ' + slinebreak + ' [hkey_classes_root\%0:s] ' + slinebreak + ' @= '%1:s ' + slinebreak + ' [hkey_ Classes_root\%1:s\defaulticon] ' + slinebreak + ' @= '%2:s,0 ' + slinebre AK + ' [Hkey_classes_root\%1:s\shell] ' + slinebreak + ' [hkey_classes_root\%1:s\shell\open] ' + sLi
Nebreak + ' [Hkey_classes_root\%1:s\shell\open\command] ' + slinebreak + ' @= '%3:s ';
  var regstr:string;
  STR3, str4:string;
regtmpfile:string;
  Begin STR3: = Aapppath.replace (' \ ', ' \ \ '); STR4: = Format ('%s ' '%%1 ', [STR3]).
  Replace (' "', '; ');
  REGSTR: = Format (NREGFMT, [Aext, Aappname, STR3, STR4]);
  Regtmpfile: = Tpath.gettemppath + ' Regtmp.reg ';
    With Tstringlist.create do begin Text: = REGSTR;
    SaveToFile (Regtmpfile);
  Free;
  End
  ShellExecute (0, Nil, Pchar (regtmpfile), nil, nil, SW_SHOWNORMAL); SHChangeNotify (shcne_assocchanged, shcnf_idlist, nil, nil);


Refresh icon display end;
Procedure Tform1.formcreate (Sender:tobject);
var s:string;
  Begin S: = PARAMSTR (1);
If FileExists (s) then Memo1.Lines.LoadFromFile (s);

End Execute the registration function;
After execution, you can arbitrarily modify the suffix of a text file to TST, and then double-click the test procedure Tform1.button1click (sender:tobject);
 Begin RegApp ('. TST ', ' MyApp1 ', application.exename);

Assuming the program name is MYAPP1, the suffix of the file to be opened is. TST End; End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.