Solved

Shortcuts

Posted on 2004-09-25
1
258 Views
Last Modified: 2010-04-05
How can I create shortcuts for a file in the desktop, the quick launch bar and also in the start menu programs folder, like this: Start->Programs->My programs file->Main file
All this must be done by a program, not manually.

                 
0
Comment
Question by:lobo_estepario
1 Comment
 
LVL 6

Accepted Solution

by:
Stuart_Johnson earned 50 total points
ID: 12154182
I don't know where I leeched this code from, but I've had it for ages and it does work very well.

procedure TMainForm.CreateShortcut(SourceFileName, Title: string; Location:
  ShortcutType; SubDirectory : string);
var
  MyObject : IUnknown;
  MySLink  : IShellLink;
  MyPFile  : IPersistFile;
  Directory,
  LinkName  : string;
  WFileName : WideString;
  MyReg,
  QuickLaunchReg : TRegIniFile;
begin
  MyObject := CreateComObject(CLSID_ShellLink);
  MySLink := MyObject as IShellLink;
  MyPFile := MyObject as IPersistFile;

  MySLink.SetPath(PChar(SourceFileName));

  MyReg := TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\Explorer');
  try
   LinkName := ChangeFileExt(SourceFileName, '.lnk');
   LinkName := ExtractFileName(LinkName);
   case Location of
     _DESKTOP    : Directory := MyReg.ReadString('Shell Folders', 'Desktop', '');
     _STARTMENU  : Directory := MyReg.ReadString('Shell Folders', 'Start Menu', '');
     _SENDTO     : Directory := MyReg.ReadString('Shell Folders', 'SendTo', '');
     _QUICKLAUNCH:
       begin
         QuickLaunchReg := TRegIniFile.Create('Software\MicroSoft\Windows\CurrentVersion\GrpConv');

         try
           Directory := QuickLaunchReg.ReadString('MapGroups', 'Quick Launch', '');
         finally
           QuickLaunchReg.Free;
         end; {try..finally}
       end; {case _QUICKLAUNCH}
   end; {case}
   if Directory <> '' then
     begin
       if SubDirectory <> '' then
        WFileName := Directory + '\'+ SubDirectory +'\' + LinkName
       else
        WFileName := Directory + '\' + LinkName;
       MyPFile.Save(PWChar(WFileName), False);
     end; {Directory <> ''}
 finally
   MyReg.Free;
 end; {try..finally}
end; {CreateShortcut}

Hope this helps,

Stuart.
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

Suggested Solutions

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

23 Experts available now in Live!

Get 1:1 Help Now