如何用代码创建应用程序的桌面快捷方式,或创建一个指向某一网页的桌面快捷方式?

解决方案 »

  1.   

    例子,将本应用程序Project1.exe快捷方式加到桌面:
    uses 
      ShlObj, ActiveX, ComObj;procedure TForm1.Button1Click(Sender: TObject);
    var
      MyObject : IUnknown;
      MySLink : IShellLink;
      MyPFile : IPersistFile;
      FileName : String;
      DesktopDir : PChar;
      WFileName : WideString;
    begin
      MyObject := CreateComObject(CLSID_ShellLink);
      MySLink := MyObject as IShellLink;
      MyPFile := MyObject as IPersistFile;
      FileName := ParamStr(0);  with MySLink do begin
        SetPath(PChar(ParamStr(0)));
        SetWorkingDirectory(PChar(ExtractFilePath(ParamStr(0))));
      end;  GetMem(DesktopDir, MAX_PATH);
      SHGetSpecialFolderPath(0, DesktopDir, CSIDL_DESKTOP, False);
      WFileName := DesktopDir + '\快捷方式.lnk';
      FreeMem(DesktopDir);
      MyPFile.Save(PWChar(WFileName), False);
    end;————————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    ————————————————————————————————————