Solved

Shortcuts

Posted on 2004-09-25
1
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

717 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