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
Antwort Antwort
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
LTE5

Registriert seit: 13. Nov 2017
355 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#2

AW: Verknüpfung (.lnk) Datei erzeugen

  Alt 29. Jan 2018, 19:20
So?

Delphi-Quellcode:
function createLink(const aFileName, aLinkFileName, aParameter, aLinkDestination: string): Boolean;
var
 psl: IShellLink;
 ppf: IPersistFile;
begin
 Result := False;

 if Succeeded(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_inPROC_SERVER, IID_IShellLinkW, psl)) then
  begin
   psl.SetPath(PWideChar(aFileName));
   psl.SetArguments(PWideChar(aParameter));
   psl.SetWorkingDirectory(PWideChar(ExtractFilePath(aFileName)));

   if Succeeded(psl.QueryInterface(IPersistFile, ppf)) then
    begin
     ppf.Save(PWideChar(aLinkDestination + aLinkFileName + '.lnk'), True);
     Result := True;
    end;
  end;
end;

function GetDesktopFolder: string;
var
 LStr: array [0 .. MAX_PATH] of Char;
begin
 SetLastError(ERROR_SUCCESS);
 Result := '';
 if SHGetFolderPath(0, CSIDL_DESKTOPDIRECTORY, 0, 0, @LStr) = S_OK then
  Result := IncludeTrailingPathDelimiter(LStr);
end;

function GetStartMenuFolder: string;
var
 LStr: array [0 .. MAX_PATH] of Char;
begin
 SetLastError(ERROR_SUCCESS);
 Result := '';
 if SHGetFolderPath(0, CSIDL_STARTMENU, 0, 0, @LStr) = S_OK then
  Result := IncludeTrailingPathDelimiter(LStr);
end;

B := createLink(ParamStr(0), 'Shortcut Name', 'Parameter', GetDesktopFolder);
Sieht man auch hier
http://www.delphipraxis.net/191958-v...erstellen.html
  Mit Zitat antworten Zitat
Fukiszo
(Gast)

n/a Beiträge
 
#3

AW: Verknüpfung (.lnk) Datei erzeugen

  Alt 29. Jan 2018, 19:38
Vielen Dank für die schnelle Antwort!
Hast Du zufällig auch eine Routine rumliegen mit der man den Inhalt einer .lnk Datei wieder auslesen kann?

Grüße
  Mit Zitat antworten Zitat
LTE5

Registriert seit: 13. Nov 2017
355 Beiträge
 
Delphi 10.2 Tokyo Starter
 
#4

AW: Verknüpfung (.lnk) Datei erzeugen

  Alt 29. Jan 2018, 19:41
Guck mal hier. Könnte deine Frage beantworten

How can You Open and Edit Windows .lnk Shortcut Files?
  Mit Zitat antworten Zitat
Fukiszo
(Gast)

n/a Beiträge
 
#5

AW: Verknüpfung (.lnk) Datei erzeugen

  Alt 29. Jan 2018, 19:56
Dort wird beschrieben wie man eine .lnk Datei mit Notepad und Hexeditor bearbeitet,
ich wollt schon innerhalb Delphi bleiben und hat gehofft das es da auch so eine "simple" methode gibt.
Ziel sollte sein eine .lnk datei auszuwerten und falls ein update nötig ist einfach eine neue erstellen.

Ich schau mal was ich mit der .pdf von microsoft anfangen kann um es mit Delphi zu realisieren.

Grüße


edit:
hab was passendes gefunden:

Delphi-Quellcode:
function GetLinkInfo(WinhWnd:HWND;LnkObj:string):String;
var
  hres : HRESULT;
  psl : IShellLink;
  ppf : IPersistFile;
  wfd : Win32_Find_Data;
  Path : array[0..MAX_PATH] of Char;
begin
  result := '????';
  //initializes the Component Object Model(COM) library
  CoInitialize(nil);
  // Call CoCreateInstance to obtain the IShellLink Interface pointer.
  hres:=CoCreateInstance(CLSID_ShellLink, nil,
                              CLSCTX_INPROC_SERVER, IID_IShellLinkA, psl);
  if NOT SUCCEEDED(hres) then exit;
  // The IShellLink Interface supports the IPersistFile
  // interface. Get an interface pointer to it.
  hres:=psl.QueryInterface(IID_IPersistFile,ppf);
  if SUCCEEDED(hres) then begin
    // Convert the given link name string to wide character string.
    // and Load the file.
    hres:=ppf.Load(StringToOLEStr(LnkObj),STGM_READ);
    if SUCCEEDED(hres) then begin
      // Resolve the link by calling the Resolve() interface function.
      hres:=psl.Resolve(WinhWnd,SLR_ANY_MATCH OR SLR_NO_UI);
      if SUCCEEDED(hres) then begin
        hres:=psl.GetPath(Path,MAX_PATH,wfd,SLGP_SHORTPATH);
        if SUCCEEDED(hres) then result:=Path;
      end;
    end;
  end;
end;

Geändert von Fukiszo (29. Jan 2018 um 20:06 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort


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 13:12 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