Solved

Windows shortcut/lnk files...

Posted on 1998-09-22
3
802 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

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

Suggested Solutions

Title # Comments Views Activity
Best Firemonkey component pack 1 118
Delphi application Soap connection 5 118
Correct Component for Shopping Cart. 2 112
Dev Express grid collapse 2 45
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 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