Solved

Shortcuts

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

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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 …

803 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