Solved

Windows shortcut/lnk files...

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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