codebutcher 发表于 2013-4-1 15:06

创建程序桌面快捷方式

本帖最后由 codebutcher 于 2013-4-1 15:11 编辑

//本例程以创建Internet Explorer桌面快捷方式为例
//Delphi XE3 With Update2编译通过
//以创建Internet Explorer快捷方式到桌面为例
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,ShlObj, ActiveX, ComObj, Vcl.StdCtrls;
type
TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
private
    { Private declarations }
public
    { Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject) ;
var
    IObject : IUnknown;
    ISLink : IShellLink;
    IPFile : IPersistFile;
    PIDL : PItemIDList;
    InFolder : array of Char;
    TargetName : String;
    LinkName : WideString;
begin
    TargetName := 'C:\Program Files\Internet Explorer\iexplore.exe';
    {Use TargetName:=ParamStr(0) which
    returns the path and file name of the
    executing program to create a link to your
    Application}
    IObject := CreateComObject(CLSID_ShellLink) ;
    ISLink := IObject as IShellLink;
    IPFile := IObject as IPersistFile;
    with ISLink do
    begin
      SetPath(pChar(TargetName)) ;
      SetWorkingDirectory(pChar(ExtractFilePath(TargetName))) ;
    end;
    // if we want to place a link on the Desktop
    SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL) ;
    SHGetPathFromIDList(PIDL, InFolder) ;
    {
   or if we want a link to appear in
   some other, not-so-special, folder:
   InFolder := 'C:\SomeFolder'
    }
    LinkName := InFolder + '\Internet Explorer.lnk';
    IPFile.Save(PWChar(LinkName), false) ;
    Button1.Enabled:=false;
end;
end.













淡然出尘 发表于 2013-4-1 15:30

欢迎访问:http://www.52pojie.cn/thread-180373-1-1.html
页: [1]
查看完整版本: 创建程序桌面快捷方式