Réponse acceptée !
Salut,
voici un petit bout de code que j'avais utilisé il y a longtemps déjà
la base du code n'est pas de moi (je l'avais récuperé je ne sais plus ou sur le net) je l'ai juste complété et réduit.
il existe peut être méthode plus courte mais en attendant elle fonctionne (testé Ok sous D4 pro):
Tu mets un Bouton un Label et un Mémo sur une form et tu complètes comme ceci :
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure GetLink(LinkPath: String);
private
{ Déclarations privées }
...
implementation
{$R *.DFM}
Uses ComObj, // pour IUnknown
ActiveX, // pour IPersistFile
ShlObj, // pour IShellLink
Menus; // pour ShortCutToKey
procedure TForm1.GetLink(LinkPath: String);
var
AnObj : IUnknown;
ShLink : IShellLink;
PFile : IPersistFile;
WFileName : WideString;
WorkingDir,Target ,IconLocation,
Description, Arguments : String;
X1 : Array [0..255] Of Char;
Data : TWin32FindData;
App1 ,ShowCmd,IconNumber : Integer;
W ,HotKey : Word;
TheKey : Word;
TheShiftState : TShiftState;
begin
if UpperCase(ExtractFileExt(LinkPath)) <> '.LNK'then
begin
ShowMessage('Erreur: '+LinkPath+' n''est pas unRacourci valide');
exit; // Si ce n'est pas un racourci on quitte
end;
// access to the two interfaces of the object
AnObj := CreateComObject(CLSID_ShellLink);
ShLink := AnObj as IShellLink;
PFile := AnObj as IPersistFile;
// Load with a WideString filename
WFileName := LinkPath;
PFile.Load(PWChar(WFileName),STGM_READ);
Shlink.GetDescription(@X1,MAX_PATH);
Description := StrPas(@X1);
SHlink.GetIconLocation(@X1,MAX_PATH,App1);
IconLocation := StrPas(@X1);
IconNumber := App1;
App1 := 0;
SHlink.GetShowCmd(App1);
ShowCmd := App1;
W := 0;
SHlink.GetHotKey(W);
HotKey := W;
SHlink.GetArguments(@X1,MAX_PATH );
Arguments := StrPas(@X1);
SHLink.GetWorkingDirectory(@X1,MAX_PATH );
WorkingDir := StrPas(@X1);
SHlink.GetPath( @X1,MAX_PATH,Data,SLGP_UNCPRIORITY);
Target := StrPas(@X1);
Label1.Caption:=StrPas(@X1)+' '+IntToStr(App1);
ShortCutToKey(HotKey, TheKey, TheShiftState);
With Memo1.Lines do
Begin
Clear;
Add('Cible : '+ Target );
Add('Repertoire : '+ WorkingDir );
Add('Icon : '+ IconLocation );
Add('N° Icon : '+ IntToStr(IconNumber) );
Add('Hot Key : '+ ShortCutToText(W) );
Add('Arguments : '+ Arguments );
Add('Description : '+ Description );
Add('ShowCmd : '+ IntToStr(ShowCmd) );
End;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
GetLink('C:\Documents and Settings\Administrateur\Bureau\PSPad.lnk');
end;
end.
Voilà c'est tout
n'oubliez pas de cliquer sur
Réponse Acceptée
si elle vous convient
@+
Cirec