Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Windows API / MS.NET Framework API (https://www.delphipraxis.net/20-library-windows-api-ms-net-framework-api/)
-   -   Delphi Eine Verknüpfung erstellen (https://www.delphipraxis.net/21153-eine-verknuepfung-erstellen.html)

Matze 28. Apr 2004 16:29


Eine Verknüpfung erstellen
 
Delphi-Quellcode:
uses
 ActiveX;

function CreateLink(lpszPathObj,lpszPathLink,
  lpszDesc: string):Boolean;
var
  psl: IShellLink;
  ppf: IPersistFile;

const
  IID_IPersistFile:
     TGUID = (D1:$0000010B;
              D2:$0000;
              D3:$0000;
              D4:($C0,$00,$00,$00,$00,$00,$00,$46));
begin
  result := False;
  if SUCCEEDED(CoCreateInstance(CLSID_ShellLink,
                                nil,
                                CLSCTX_INPROC_SERVER,
                                IID_IShellLinkA,
                                psl)) then
    begin
      psl.SetPath(PChar(lpszPathObj));
      psl.SetDescription(PChar(lpszDesc));
      if SUCCEEDED(psl.QueryInterface(IID_IPersistFile,
                   ppf)) then
        begin
          ppf.Save(StringToOLEStr(lpszPathLink),TRUE);
          Result := true;
          ppf._Release; //---> Runtime-Error wenn aktiv
        end;
    end;
  psl._Release; // ---> Runtime-Error wenn aktiv
end;


//Aufruf:
  if CreateLink('d:\Datei.exe', 'c:\Verknüpfung.exe', 'Verknüpfung') then
    MessageDlg('Verknüpfung angelegt', mtInformation, [mbOk], 0);
Benötigt wird die Unit ShlOBJ.

Dieser Code wurde hier von FuckRacism veröffentlicht, stammt jedoch ursprünglich von Delphi-Treff.

[edit=Chakotay1308]Mfg, Chakotay1308[/edit]
[edit=sakura] uses hinzugefügt. Mfg, sakura[/edit]


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:51 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz