Solved

*.lnk file format

Posted on 1998-03-12
10
539 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi with SQL Natvie Client 15 86
Newbie Thread Programming 1 139
Strange behavior when a form is closed 6 51
Downloading email attachments 2 67
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

14 Experts available now in Live!

Get 1:1 Help Now