Solved

Windows shortcut/lnk files...

Posted on 1998-09-22
3
797 Views
Last Modified: 2008-03-03
Is there a way, either through Delphi (D3) or the Win API, that I can either create a desktop shortcut/lnk file or just modify the path program path in an existing shortcut/lnk? I would prefer to create the entire file. TANKS in advance.
0
Comment
Question by:TonyMalo
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 100 total points
ID: 1340529
Hi

The following code can be used to create a shortcut to Notepad on your desktop (assuming your desktop path is C:\Windows\Desktop).

var
  SL: IShellLink;
  PF: IPersistFile;
  wPath: array[0..MAX_PATH] of WideChar;
begin
  SL := CreateComObject(CLSID_ShellLink) as IShellLink;
  SL.SetPath(PChar('C:\Windows\Notepad.exe'));
  PF := (SL as IPersistFile);
  MultiByteToWideChar(CP_ACP, 0, PChar('C:\Windows\Desktop\Notepad.lnk'), -1, wPath, MAX_PATH);
  PF.Save(wPath, True);
end;

You will need to add ComObj, ShlObj and ActiveX to your uses clause.

Regards,
JB
0
 

Expert Comment

by:bome
ID: 1340530
just a comment:
in serious programs, DON'T use fixed paths for the windows install dir. There are enough programs (especially professional programs) that don't handle that right... for example I have autostart entries in 3 languages, "Program Files" directories in 3 langages and 2 partitions, etc...
I certainly don't mean you, JimBob, because that serves as an example.
Is it..well... just a comment !

bome

0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1340531
> Is it..well... just a comment !

And a good comment too!  As you say, there are too many programs that don't handle directories properly.

My home PC has 1 profile for me, and another for my wife, so that PC doesn't have a C:\Windows\Desktop folder.
My desktop is actually C:\Windows\Profiles\David\Desktop.

Cheers,
Dave
0

Featured Post

IT, Stop Being Called Into Every Meeting

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!

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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