Solved

*.lnk file format

Posted on 1998-03-12
10
538 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now