Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to create .LNK files?

Posted on 1999-07-21
6
Medium Priority
?
392 Views
Last Modified: 2010-04-04
Hi there!
How to easily create a link file (.LNK)?
Suppose I want to put a link in the Windows Startup folder to my program, how to do that?
Thanks in advance!
0
Comment
Question by:mauromol
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1390137
0
 
LVL 10

Accepted Solution

by:
Lischke earned 400 total points
ID: 1390138
hi mauromol,

use this function to create your link file:

function MakeStartMenuLink(Name, Folder, ExeName, WorkingDir: String): Integer;

// Name       : name of the link without the ".lnk" extension
// Folder     : folder in the startmenu where the link should be placed in
// ExeName    : filename and path of the executable
// WorkingDir : working directory of the program

var AReg      : TRegIniFile;
    AObject   : IUnknown;
    ASLink    : IShellLink;
    APFile    : IPersistFile;
    Directory : String;
    WFileName : WideString;
    R         : HRESULT;

begin
  Result := erOK;
  AObject := CreateComObject(CLSID_ShellLink);
  ASLink := AObject as IShellLink;
  APFile := AObject as IPersistFile;
  with ASLink do begin
    SetArguments('');
    SetPath(PChar(ExeName));
    SetWorkingDirectory(PChar(WorkingDir));
  end;

  AReg := TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\Explorer');
  try
    Directory := AReg.ReadString('Shell Folders', 'Programs', '')+'\'+Folder;
    if not DirectoryExists(Directory) then Result := erDirectory;
    if (Length(Name) > 0) and (Name[Length(Name)] = '\') then Delete(Name, Length(Name), 1);
    WFileName := Directory+'\'+Name+'.lnk';
    R := APFile.Save(PWChar(WFileName), False);
    if R = E_FAIL then Result := Result or erFile;
  finally
    AReg.Free;
  end;
end;

Ciao, Mike

0
 
LVL 15

Expert Comment

by:simonet
ID: 1390139
I was here!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:mauromol
ID: 1390140
Thank you very much to both meikl and Mike (how did you know I'm Italian? :-)
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1390141
mauromol, I didn't know that you are an Italian, where have you got the impression from I'd knew it?

Ciao, Mike

PS: Aah, perhaps you thought this because of my "Ciao"? Well, this is my usual greeting phrase I'm using now since about 5 years...
0
 

Author Comment

by:mauromol
ID: 1390142
Yes, it was "Ciao" :-)
Bye! Mauro.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

662 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