I was using code as found on the net via google...as a matter of
fact it was on About.com! And it matched another example I found as well!
Their example when using ShGetSpecialFolderLocation was to place a shortcut
on the desktop. And their LinkName was a combination of InFolder and the
shortcut filename as I mentioned I had tried. That, as I said, results in a
shortcut to the folder the Exe is in! Nor did their code free the PIDL.
All I did was change to a different folder constant.
In any case I came up with a much better solution...one using string
paths instead of the special folder constants. And it works very well.
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 Rob Kennedy
Sent: Saturday, April 01, 2006 1:22 PM
To: Borland's Delphi Discussion List
Subject: Re: Problems creating shortcut
Robert Meek wrote:
> 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.
You should know by now that "not working" is a lousy description of the
problem. What happens?
> 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!
At what point in the code do you tell the shortcut that it should point
at the EXE name and not the entire folder path?
> begin
> IObject := CreateComObject(CLSID_ShellLink);
> ISLink := IObject as IShellLink;
> IPFile := IObject as IPersistFile;
>
> with ISLink do begin
> SetPath(pChar(AppPath));
> SetWorkingDirectory
> (pChar(AppPath));
> end;
Those lines set two fields of the shortcut object to refer to the
application's path + '\'.
> // if we want to place a link in a special folder
> SHGetSpecialFolderLocation(0, CSIDL_STARTUP, PIDL);
> SHGetPathFromIDList(PIDL, InFolder);
If you're going to use ShGetSpecialFolderLocation instead of
ShGetSpecialFolderPath, you need to remember to free the PIDL when
you're finished with it. For example:
http://www.cs.wisc.edu/~rkennedy/my-documents
> TargetName := Application.ExeName;
> LinkName := JustNameL(TargetName) + '.lnk';
> IPFile.Save(PWideChar(LinkName), True);
That saves the shortcut object to a particular file.
--
Rob
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi