Board index » delphi » Creating shortcut from Delphi

Creating shortcut from Delphi

Does anybody know how to create shortcuts on the windows start menu using
delphi??

I am writing an installation program.  I Can create the file associations
throught editing the registry, also I can create the Start menu | programs
group but not the .lnk files.

Please help me.

 

Re:Creating shortcut from Delphi


Chezz <ch...@callistocs.freeserve.co.uk> skrev i
diskussionsgruppsmeddelandet:85v72p$er...@news5.svr.pol.co.uk...

Quote
> Does anybody know how to create shortcuts on the windows start menu using
> delphi??

> I am writing an installation program.  I Can create the file associations
> throught editing the registry, also I can create the Start menu | programs
> group but not the .lnk files.

> Please help me.

This is what I use:

function CreateLink(FileName, LinkArguments, LinkPath, LinkDescription,
LinkIcon: string): HRESULT;
  var
    IU: IUnknown;
    ISH: IShellLink;
    IPF: IPersistFile;
    WideBuffer: array [0..MAX_PATH - 1] of Word;
begin
  IU := CreateComObject(CLSID_ShellLink);
  ISH := IU as IShellLink;
  IPF := IU as IPersistFile;
  ISH.SetArguments(PChar(LinkArguments));
  ISH.SetPath(PChar(FileName));
  ISH.SetDescription(PChar(LinkDescription));
  ISH.SetIconLocation(PChar(LinkIcon), 0);
  MultiByteToWideChar(CP_ACP, 0, PChar(LinkPath), -1, @WideBuffer,
MAX_PATH);
  Result := IPF.Save(@WideBuffer, False);
  IU._Release;
end;

Re:Creating shortcut from Delphi


Thanx Henrik.

Please could you tell me if a need to add units to the uses clause, other
than comobj.  I can't seem to get it to work.

I have not used com objects before.  I am using Delphi 3.

Thanx again for your help.

Quote
Henrik Palmr <henrik.pal...@swipnet.se> wrote in message

news:D_Ig4.2284$Q4.4929@nntpserver.swip.net...
Quote

> Chezz <ch...@callistocs.freeserve.co.uk> skrev i
> diskussionsgruppsmeddelandet:85v72p$er...@news5.svr.pol.co.uk...
> > Does anybody know how to create shortcuts on the windows start menu
using
> > delphi??

> > I am writing an installation program.  I Can create the file
associations
> > throught editing the registry, also I can create the Start menu |
programs
> > group but not the .lnk files.

> > Please help me.

> This is what I use:

> function CreateLink(FileName, LinkArguments, LinkPath, LinkDescription,
> LinkIcon: string): HRESULT;
>   var
>     IU: IUnknown;
>     ISH: IShellLink;
>     IPF: IPersistFile;
>     WideBuffer: array [0..MAX_PATH - 1] of Word;
> begin
>   IU := CreateComObject(CLSID_ShellLink);
>   ISH := IU as IShellLink;
>   IPF := IU as IPersistFile;
>   ISH.SetArguments(PChar(LinkArguments));
>   ISH.SetPath(PChar(FileName));
>   ISH.SetDescription(PChar(LinkDescription));
>   ISH.SetIconLocation(PChar(LinkIcon), 0);
>   MultiByteToWideChar(CP_ACP, 0, PChar(LinkPath), -1, @WideBuffer,
> MAX_PATH);
>   Result := IPF.Save(@WideBuffer, False);
>   IU._Release;
> end;

Re:Creating shortcut from Delphi


Chezz <ch...@callistocs.freeserve.co.uk> skrev i
diskussionsgruppsmeddelandet:861enh$52...@news7.svr.pol.co.uk...

Quote
> Thanx Henrik.

> Please could you tell me if a need to add units to the uses clause, other
> than comobj.  I can't seem to get it to work.

> I have not used com objects before.  I am using Delphi 3.

> Thanx again for your help.

Sorry, I forgot that part...

uses
  Windows, ComObj, ShlObj, ActiveX;

Re:Creating shortcut from Delphi


Thanx.
Quote
Henrik Palmr <henrik.pal...@swipnet.se> wrote in message

news:7qYg4.2754$Q4.5754@nntpserver.swip.net...
Quote

> Chezz <ch...@callistocs.freeserve.co.uk> skrev i
> diskussionsgruppsmeddelandet:861enh$52...@news7.svr.pol.co.uk...
> > Thanx Henrik.

> > Please could you tell me if a need to add units to the uses clause,
other
> > than comobj.  I can't seem to get it to work.

> > I have not used com objects before.  I am using Delphi 3.

> > Thanx again for your help.

> Sorry, I forgot that part...

> uses
>   Windows, ComObj, ShlObj, ActiveX;

Re:Creating shortcut from Delphi


By using the "Find in Files" option in the IDE I found out that the Windows,
ShlObj, ActiveX and ComObj units are needed.

Robin Gerrets
R.Gerr...@student.nyenrode.nl

"Chezz" <ch...@callistocs.freeserve.co.uk> schreef in bericht
news:861enh$52p$1@news7.svr.pol.co.uk...
| Thanx Henrik.
|
| Please could you tell me if a need to add units to the uses clause, other
| than comobj.  I can't seem to get it to work.
|
| I have not used com objects before.  I am using Delphi 3.
|
| Thanx again for your help.
|
| Henrik Palmr <henrik.pal...@swipnet.se> wrote in message
| news:D_Ig4.2284$Q4.4929@nntpserver.swip.net...
| >
| > Chezz <ch...@callistocs.freeserve.co.uk> skrev i
| > diskussionsgruppsmeddelandet:85v72p$er...@news5.svr.pol.co.uk...
| > > Does anybody know how to create shortcuts on the windows start menu
| using
| > > delphi??
| > >
| > > I am writing an installation program.  I Can create the file
| associations
| > > throught editing the registry, also I can create the Start menu |
| programs
| > > group but not the .lnk files.
| > >
| > > Please help me.
| >
| > This is what I use:
| >
| > function CreateLink(FileName, LinkArguments, LinkPath, LinkDescription,
| > LinkIcon: string): HRESULT;
| >   var
| >     IU: IUnknown;
| >     ISH: IShellLink;
| >     IPF: IPersistFile;
| >     WideBuffer: array [0..MAX_PATH - 1] of Word;
| > begin
| >   IU := CreateComObject(CLSID_ShellLink);
| >   ISH := IU as IShellLink;
| >   IPF := IU as IPersistFile;
| >   ISH.SetArguments(PChar(LinkArguments));
| >   ISH.SetPath(PChar(FileName));
| >   ISH.SetDescription(PChar(LinkDescription));
| >   ISH.SetIconLocation(PChar(LinkIcon), 0);
| >   MultiByteToWideChar(CP_ACP, 0, PChar(LinkPath), -1, @WideBuffer,
| > MAX_PATH);
| >   Result := IPF.Save(@WideBuffer, False);
| >   IU._Release;
| > end;
| >
| >
| >
|
|

Re:Creating shortcut from Delphi


Still having problems!

Tried the function, got an Access Violation message.  What am I doing
wrong??

What should I enter for the 'arguments' string??

Quote
Henrik Palmr <henrik.pal...@swipnet.se> wrote in message

news:7qYg4.2754$Q4.5754@nntpserver.swip.net...
Quote

> Chezz <ch...@callistocs.freeserve.co.uk> skrev i
> diskussionsgruppsmeddelandet:861enh$52...@news7.svr.pol.co.uk...
> > Thanx Henrik.

> > Please could you tell me if a need to add units to the uses clause,
other
> > than comobj.  I can't seem to get it to work.

> > I have not used com objects before.  I am using Delphi 3.

> > Thanx again for your help.

> Sorry, I forgot that part...

> uses
>   Windows, ComObj, ShlObj, ActiveX;

Other Threads