Just letting all know that I found a much easier way of creating
shortcuts.  One in which you don't have to deal with all the typecasting.
Here's the code in case anyone is interested:

//Don't forget to add ShlObj, ComObj and ActiveX to the uses clause!

function CreateShellLink(const Filename, Description, ShortcutTo,
Parameters, WorkingDir, IconFilename: String; const IconIndex, ShowCmd:
Integer): Boolean;
{ Creates a lnk file named Filename, with a description of Description,
which
 points to ShortcutTo.}
var
 Obj: IUnknown;
 SL: IShellLink;
 PF: IPersistFile;
 WideFilename: WideString;
begin
 Obj := CreateComObject(CLSID_ShellLink);
 SL := Obj as IShellLink;
 SL.SetPath(PChar(ShortcutTo));
 SL.SetArguments(PChar(Parameters));
 if WorkingDir <> '' then
   SL.SetWorkingDirectory(PChar(WorkingDir));
 if IconFilename <> '' then
   SL.SetIconLocation(PChar(IconFilename), IconIndex);
 SL.SetShowCmd(ShowCmd);
 if Description <> '' then
   SL.SetDescription(PChar(Description));
 PF := Obj as IPersistFile;
 WideFilename := Filename;
 Result := SUCCEEDED(PF.Save(PWideChar(WideFilename), True));
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


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Robert Meek
Sent: Friday, March 31, 2006 5:41 PM
To: [email protected]
Subject: Problems creating shortcut

        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

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

Reply via email to