AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Verknüpfung auslesen und probleme
Thema durchsuchen
Ansicht
Themen-Optionen

Verknüpfung auslesen und probleme

Ein Thema von delphinia · begonnen am 13. Mär 2006 · letzter Beitrag vom 10. Apr 2006
Antwort Antwort
delphinia

Registriert seit: 16. Feb 2006
444 Beiträge
 
Delphi 11 Alexandria
 
#1

Verknüpfung auslesen und probleme

  Alt 13. Mär 2006, 10:41
Auslesen der Informationen einer *.lnk wie folgt:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ShlObj, ComObj, ActiveX, CommCtrl;

type
 PShellLinkInfoStruct = ^TShellLinkInfoStruct;
  TShellLinkInfoStruct = record
    FullPathAndNameOfLinkFile: array[0..MAX_PATH] of Char;
    FullPathAndNameOfFileToExecute: array[0..MAX_PATH] of Char;
    ParamStringsOfFileToExecute: array[0..MAX_PATH] of Char;
    FullPathAndNameOfWorkingDirectroy: array[0..MAX_PATH] of Char;
    Description: array[0..MAX_PATH] of Char;
    FullPathAndNameOfFileContiningIcon: array[0..MAX_PATH] of Char;
    IconIndex: Integer;
    HotKey: Word;
    ShowCommand: Integer;
    FindData: TWIN32FINDDATA;
  end;

  
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure GetLinkInfo(lpShellLinkInfoStruct: PShellLinkInfoStruct);
var
  ShellLink: IShellLink;
  PersistFile: IPersistFile;
  AnObj: IUnknown;
begin
  // access to the two interfaces of the object
  AnObj := CreateComObject(CLSID_ShellLink);
  ShellLink := AnObj as IShellLink;
  PersistFile := AnObj as IPersistFile;

  // Opens the specified file and initializes an object from the file contents.
  PersistFile.Load(PWChar(WideString(lpShellLinkInfoStruct^.FullPathAndNameOfLinkFile)), 0);
  with ShellLink do
  begin
    // Retrieves the path and file name of a Shell link object.
    GetPath(lpShellLinkInfoStruct^.FullPathAndNameOfFileToExecute,
      SizeOf(lpShellLinkInfoStruct^.FullPathAndNameOfLinkFile),
      lpShellLinkInfoStruct^.FindData,
      SLGP_UNCPRIORITY);

    // Retrieves the description string for a Shell link object.
    GetDescription(lpShellLinkInfoStruct^.Description,
      SizeOf(lpShellLinkInfoStruct^.Description));

    // Retrieves the command-line arguments associated with a Shell link object.
    GetArguments(lpShellLinkInfoStruct^.ParamStringsOfFileToExecute,
      SizeOf(lpShellLinkInfoStruct^.ParamStringsOfFileToExecute));

    // Retrieves the name of the working directory for a Shell link object.
    GetWorkingDirectory(lpShellLinkInfoStruct^.FullPathAndNameOfWorkingDirectroy,
      SizeOf(lpShellLinkInfoStruct^.FullPathAndNameOfWorkingDirectroy));

    // Retrieves the location (path and index) of the icon for a Shell link object.
    GetIconLocation(lpShellLinkInfoStruct^.FullPathAndNameOfFileContiningIcon,
      SizeOf(lpShellLinkInfoStruct^.FullPathAndNameOfFileContiningIcon),
      lpShellLinkInfoStruct^.IconIndex);

    // Retrieves the hot key for a Shell link object.
    GetHotKey(lpShellLinkInfoStruct^.HotKey);

    // Retrieves the show (SW_) command for a Shell link object.
    GetShowCmd(lpShellLinkInfoStruct^.ShowCommand);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
const
  br = #13#10;
var
  LinkInfo: TShellLinkInfoStruct;
  s: string;

begin
 Memo1.Clear;
  FillChar(LinkInfo, SizeOf(LinkInfo), #0);
  StrLCopy(LinkInfo.FullPathAndNameOfLinkFile, PChar(Edit1.text), 255);

  GetLinkInfo(@LinkInfo);
  with LinkInfo do
    s := FullPathAndNameOfLinkFile + br +
      FullPathAndNameOfFileToExecute + br +
      ParamStringsOfFileToExecute + br +
      FullPathAndNameOfWorkingDirectroy + br +
      Description + br +
      FullPathAndNameOfFileContiningIcon + br +
      IntToStr(IconIndex) + br +
      IntToStr(LoByte(HotKey)) + br +
      IntToStr(HiByte(HotKey)) + br +
      IntToStr(ShowCommand) + br +
      FindData.cFileName + br +
      FindData.cAlternateFileName;
  Memo1.Lines.Add(s);
end;

end.


Das Problem es funktioniert nicht richtig!
Erstelle ich einen zB.: einen Link mit Windowshilfe - Rechtklick auf ein Icon und "Verknüpfung erstellen" wählen und dieses dann sogleich auslese werden mir keine Icon Informationen ausgegeben!

Erst wenn ich über die Iconeigenschaften dieser Verknüpfung ein Icon manuell wähle - bekomme ich diese Informationen auch mit dem obigen Code!

Nun meine Frage - wie kann ich besser ein Link auslesen?
Irgendwie schafft Windows das doch auch
Doreen
Gruss Doreen
  Mit Zitat antworten Zitat
shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#2

Re: Verknüpfung auslesen und probleme

  Alt 13. Mär 2006, 12:34
Ich kann dir die Unit JclShell aus der JCL 1.97 empfehlen!!
(Funktion ShellLinkResolve)
Da bekommst du 1.) gut getesteten Programmcode und 2.) eine umfangreiche aber wenig
Platz fresende Bibliothek dazu.
Andreas
  Mit Zitat antworten Zitat
delphinia

Registriert seit: 16. Feb 2006
444 Beiträge
 
Delphi 11 Alexandria
 
#3

Re: Verknüpfung auslesen und probleme

  Alt 13. Mär 2006, 14:01
danke für deinen Hinweis auf die JCL

hab es auch versucht:


Delphi-Quellcode:
function GetLinkTarget(const link: string): string;
var
  LinkInfo: TShellLink;
begin
  try
    LinkInfo.IdList := nil;
    ShellLinkResolve(Link, LinkInfo);
    result := LinkInfo.Target;
  finally
    ShellLinkFree(LinkInfo);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMEssage(GetLinkTarget('C:\t\1.lnk'));
end;
aber das geht nicht ;( - klicke ich auf den Button ist die Message leer
Doreen
Gruss Doreen
  Mit Zitat antworten Zitat
shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#4

Re: Verknüpfung auslesen und probleme

  Alt 13. Mär 2006, 14:44
OleCheck nicht vergessen:
Delphi-Quellcode:
function GetLinkTarget(const link: string): string;
var
  LinkInfo: TShellLink;
begin
  try
    LinkInfo.IdList := nil;
    OleCheck(ShellLinkResolve(Link, LinkInfo));
  //^^^^^^^^
    result := LinkInfo.Target;
  finally
    ShellLinkFree(LinkInfo);
  end;
end;
Andreas
  Mit Zitat antworten Zitat
delphinia

Registriert seit: 16. Feb 2006
444 Beiträge
 
Delphi 11 Alexandria
 
#5

Re: Verknüpfung auslesen und probleme

  Alt 13. Mär 2006, 15:11
aaaha danke

musste bisschen suchen um rauszufinden welche unit ich dafür einbinden muss.
den über die Hilfe fand ich zu OleCheck nichts.

hat jemand noch weitere Infos zu OleCheck was das ist was es macht etc. eventuell auch zu der Unit ComObj?
Doreen
Gruss Doreen
  Mit Zitat antworten Zitat
shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#6

Re: Verknüpfung auslesen und probleme

  Alt 13. Mär 2006, 15:15
Unit ComObj ist korrekt.
OleCheck prüft den Rückgabewert (Typ HRESULT) und wirft wenn nötig (z.B. LNK-Datei nicht vorhanden) eine Exception.
Andreas
  Mit Zitat antworten Zitat
renekr

Registriert seit: 27. Feb 2005
Ort: Karlsbad
534 Beiträge
 
Delphi 2007 Enterprise
 
#7

Re: Verknüpfung auslesen und probleme

  Alt 10. Apr 2006, 10:22
Hi,
kann es sein das ich mit GetLinkTarget nur den Dos filename rausbekomme?
Also mit ~~ wenn der Dateiname länger wie 8 Zeichen ist.?

Danke.
  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 09:51 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