Solved

Shortcuts

Posted on 2004-09-25
1
262 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi parse string to params 3 158
Firemonkey webbrowser scrollbars ? 1 57
Breakpoint doesn't stop in my variable 3 38
Firemonkey Listview item popup menu ? 1 38
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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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