Einzelnen Beitrag anzeigen

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