Below is the code from a unit I wanted to use to create a shortcut
to my application.  I want the shortcut to be placed in the personal startup
folder of the currently logged on username.  For some reason it's not
working.  But if I add the InFolder var to my LinkName var, as in:  LinkName
:= InFolder + JustNameL(TargetName) + '.lnk'; a shortcut does get placed in
the proper directory, but instead of the shortcut pointing to the exename,
it points to the entire folder path that the exename resides in!  Can anyone
please tell me what I'm doing wrong?  Note:  AppPath = the application's
path + '\'

unit NewShortCutU;

interface

uses Windows, SysUtils, Forms, ShlObj, ActiveX, ComObj, Ststrl;

procedure CreateShortcut(Sender: TObject);

implementation

uses
    MainF1u,
    OptionsF1u;

procedure CreateShortcut(Sender: TObject);
var
  IObject    : IUnknown;
  ISLink     : IShellLink;
  IPFile     : IPersistFile;
  PIDL       : PItemIDList;
  InFolder   : array[0..MAX_PATH] of Char;
  LinkName   : WideString;
  TargetName : String;

begin
  IObject := CreateComObject(CLSID_ShellLink);
  ISLink  := IObject as IShellLink;
  IPFile  := IObject as IPersistFile;

  with ISLink do begin
    SetPath(pChar(AppPath));
    SetWorkingDirectory
           (pChar(AppPath));
  end;

  // if we want to place a link in a special folder
  SHGetSpecialFolderLocation(0, CSIDL_STARTUP, PIDL);
  SHGetPathFromIDList(PIDL, InFolder);

  { InFolder := 'C:\Documents and Settings\' + AppUserName +
'\StartMenu\Programs\Startup'}
 
TargetName := Application.ExeName;
  LinkName := JustNameL(TargetName) + '.lnk';
  IPFile.Save(PWideChar(LinkName), True);
end;
end.

from Robert Meek dba Tangentals Design  CCopyright 2006

"When I examine myself and my methods of thought, I come to the conclusion
that the gift of Fantasy has meant more to me then my talent for absorbing
positive knowledge!"
                                                    Albert Einstein



_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to