Solved

Shortcuts

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

13 Experts available now in Live!

Get 1:1 Help Now