AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Delphi Verknüpfung (.lnk) Datei erzeugen
Thema durchsuchen
Ansicht
Themen-Optionen

Verknüpfung (.lnk) Datei erzeugen

Ein Thema von Fukiszo · begonnen am 29. Jan 2018 · letzter Beitrag vom 29. Jan 2018
 
Fukiszo
(Gast)

n/a Beiträge
 
#1

Verknüpfung (.lnk) Datei erzeugen

  Alt 29. Jan 2018, 19:13
Guten Abend,
ich bin immernoch am aufarbeiten alter Sources und bin nun hier gelandet:

Delphi-Quellcode:
function MakeALink(const sNewPathAndLinkfilename : String; pTargetPathAndFilename, pAddCommandLine,
                   pTargetWorkPath, pIconFromExe : PChar; iIconIndex : Integer; pDescription : PChar) : Boolean;
// Create the shortcut named in the LinkFileName argument, and load its data from the non-nil arguments. Return True if successful.
// small bug/feature shortpathnames are auto-expanded to long file format using quotes.
// how to:
// MakeALink ( 'sNewPathAndLinkfilename.lnk', pChar('pTargetPathAndFilename'), pChar('pAddCommandLine'), pChar('TargetWorkPath'), pChar(pIconFromExe), iIconIndex, pChar('pDescription'))
// where 'sNewPathAndLinkfilename.lnk' = Drive:\Path\to\Filename.lnk - file that we create
// 'pTargetPathAndFilename' = Drive:\Path\to\Source.ext - file that the link will be linked to
// 'pAddCommandLine' = '' - any additional Command Line Flags
// 'TargetWorkPath' = can be empty or a specific path
// 'pIconFromExe' = FileName that contain Icon (.ico/.exe./.dll etc)
// 'iIconIndex' = 0 for first Icon inside 'pIconFromExe'
// 'pDescription' = optional Description, will displayed as a hint
VAR
  vUNK : IUnknown;
  vISL : IShellLink;
  vIPF : IPersistFile;
  fNameW : ARRAY[0..MAX_PATH] OF WideChar;
begin
  Result := False;
  try
    StringToWideChar(sNewPathAndLinkfilename, fNameW, MAX_PATH);
    vUNK := CreateComObject(CLSID_ShellLink);
    vISL := vUNK AS IShellLink;
    vIPF := vUNK AS IPersistFile;
    IF pTargetPathAndFilename <> nil THEN
      IF vISL.SetPath(pTargetPathAndFilename) <> S_OK THEN Exit;
    IF pAddCommandLine <> nil THEN
      IF vISL.SetArguments(pAddCommandLine) <> S_OK THEN Exit;
    IF (pIconFromExe <> nil) THEN
      IF vISL.SetIconLocation(pIconFromExe, iIconIndex) <> S_OK THEN Exit;
    IF pTargetWorkPath <> nil THEN
      IF vISL.SetWorkingDirectory(pTargetWorkPath) <> S_OK THEN Exit;
    IF pDescription <> nil THEN
      IF vISL.SetDescription(pDescription) <> S_OK THEN Exit;
    IF vIPF.Save(@fNameW, False) <> S_OK THEN Exit;
    Result := True;
  except
    ON Exception DO;
  end;
end;
Gibt es eine komfortablere Art so etwas zu erreichen?
(Sorry falls Unicode bis jetzt noch nicht berücksichtigt wurde)

Grüße

ps:
_except
__ON Exception DO;
_end;
so wie ich es einsetze soll es so sein.

edit:
gibt es eine Möglichkeit eine .lnk Datei auch wieder einzulesen? (also die Werte innerhalb der .lnk Datei)

Geändert von Fukiszo (29. Jan 2018 um 19:16 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:30 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz