Solved

*.lnk file format

Posted on 1998-03-12
10
543 Views
Last Modified: 2010-04-06
Can someone please tell me what the file format of win95`s
Shortcut files (*.lnk) is. The people from windows95 general
have been giving me pages & pages of info on things working in C etc. not in delphi. I'm writing a instal program to instal another system on PCs and need to create a shortcut on the program startup menu.
0
Comment
Question by:Deep Diver
  • 5
  • 4
10 Comments
 
LVL 3

Expert Comment

by:williams2
ID: 1360430
You need to deal with Windows API methods to do this properly, I can see what I can find till tommorow...
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360431
If you want to know the file format : www.wotsit.demon.co.uk/wwindows/lnk.zip
Regards, Zif.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360432
Here already the way to read a Shell Link :


{
 Can't use Standard OpenDialog since it really
 opens .lnk file and returns the command string,
 associated with link.
}
unit SLI_Unit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, OLE2, ShlObj, ComCtrls, Menus;

type
  TForm1 = class(TForm)
    Edit0: TEdit;
    Button1: TButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Label7: TLabel;
    Edit1: TEdit;
    HotKey1: THotKey;
    procedure Button1Click(Sender: TObject);
    procedure ShowLinkInfo;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
   ShowLinkInfo;
end;
procedure TForm1.ShowLinkInfo;
Var
 Desc : Array[0..MAX_PATH] of Char;
 SL   : IShellLink;
 PF   : IPersistFile;
 HRES : HRESULT;
 FD   : TWin32FindData;
begin
 CoInitialize(Nil);
 HRes := COCreateInstance(CLSID_ShellLink, Nil, CLSCTX_INPROC_SERVER,
                          IID_IShellLink, SL);
 If Succeeded(HRes) Then
  Begin
   HRes := SL.QueryInterface(IID_IPersistFile, PF);
   If Succeeded(HRes) Then
    Begin
     Edit0.Text := 'D:\LINKDEMO.LNK';
     PF.Load('D:\LINKDEMO.LNK', STGM_READ);
     SL.Resolve(Handle, SLR_ANY_MATCH);
     SL.GetPath(Desc, MAX_PATH, FD, SLGP_UNCPRIORITY);
     Edit1.Text := StrPas(Desc);
     SL.GetDescription(Desc, MAX_PATH);
     Edit2.Text := StrPas(Desc);
     SL.GetWorkingDirectory(Desc, MAX_PATH);
     Edit3.Text := StrPas(Desc);
     SL.GetArguments(Desc, MAX_PATH);
     Edit4.Text := StrPas(Desc);
     PF.Release;
     SL.Release;
    End;
  End;
end;
end.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Accepted Solution

by:
ZifNab earned 200 total points
ID: 1360433
And this is the way to create a Shell Link


// Shows how to create Shell Link
unit SL_Unit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  OLE2, ShlObj, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Abort(Text : String);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
 sPath  : Array[0..MAX_PATH] of Char;
 Path   : String;
 HRes   : HRESULT;    
 SL     : IShellLink;     //ShellLink
 PF     : IPersistFile;   //  PersistentFile
begin
 GetWindowsDirectory(sPath, MAX_PATH);
 Path := StrPas(sPath);
 Path := Path + '\DESKTOP\';
 Edit1.Text := Path;

 CoInitialize(Nil);
 HRes := COCreateInstance(CLSID_ShellLink, Nil, CLSCTX_INPROC_SERVER,
                          IID_IShellLink, SL);
 If Succeeded(HRes) Then
  Begin
   HRes := SL.QueryInterface(IID_IPersistFile, PF);
   If Succeeded(HRes) Then
    Begin
     HRes := SL.SetPath('d:\windows\notepad.exe');
     If Not(Succeeded(HRes)) Then Abort('Error ShellLink.SetPath');
     HRes := SL.SetArguments('c:\autoexec.bat');
     If Not(Succeeded(HRes)) Then Abort('Error ShellLink.SetArguments');
     HRes := SL.SetDescription('Shell Link Demo');
     If Not(Succeeded(HRes)) Then Abort ('Error ShellLink.SetDesc');
     HRes := PF.Save('d:\windows\desktop\linkdemo.lnk', True);
     If Not(Succeeded(HRes)) Then Abort('Error PersistFile.Save');
     PF.Release;
     SL.Release;
    End Else Abort('Error PersistFile');
  End Else Abort('Error ShellLink');
end;

procedure TForm1.Abort;
begin
 MessageDlg(Text, mtError, [mbOk], 0);
 Close;
end;

end.

Regards Zif.

And this makes the circle round.....

Hope you've got enough information, now. C.U.

0
 

Author Comment

by:Deep Diver
ID: 1360434
Many TNX ZifNab!
I'll just be testing.
0
 

Author Comment

by:Deep Diver
ID: 1360435
We (I) have got a bit of a problem here...
I dont seem to have two files needed for this "program".
  Windows.DCU
  SHLObj.DCU

Do you know where I can find it?
0
 

Author Comment

by:Deep Diver
ID: 1360436
Oh yeh I see now I forgot to say that this needs to work in delphi 1.

regards
riaan
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360437
In D1 Windows is splitted in two parts, namely WinTypes and WinProcs.
About ShlObj i'm not sure. But you can find a version on this page :

http://www.connect.net/jordanr/

in his freeware setup program he uses this one and the program works also for D1.

So have a look.

Regards, Zif.
0
 

Author Comment

by:Deep Diver
ID: 1360438
ShlObj.dcu is wrong format according to D1

However, I'm going to award your points.
Many TNX for a good strait forward answer!

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360439
Thanks Deep Driver... If you still need help, I'm here...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question