• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

Shortcuts made in Delphi

Hello Good Experts!!!
How can i make chortcuts in Delphi?

1. I'm building a little Delphi app that installs programs on network computer like Macro Magic with network share.

2. I copy the files between share e.g c:\ drive and i want to make shortcuts automatically under Winnt\profiles.......

3. how can i do this?

Regards
Trausti
0
trausti
Asked:
trausti
  • 10
  • 5
  • 2
1 Solution
 
MadshiCommented:
Yuo can use this function to create a shortCut:

function CreateShortCut(pathObj, pathLink, desc: string) : boolean;
var sl : IShellLink;
begin
  sl:=CreateComObject(CLSID_ShellLink) as IShellLink;
  sl.SetPath(PChar(pathObj));
  sl.SetDescription(PChar(desc));
  result:=(sl as IPersistFile).Save(PWideChar(wideString(pathLink)),true) = 0;
end;

CreateShortCut('c:\winNT\calc.exe', 'c:\calc.lnk', 'Calculator');

This works only for D3-5, not with D2.

Regards, Madshi.
0
 
men xinCEOCommented:
Trausti:
Use this :

uses
  ShlObj, ActiveX, ComObj, Registry;

....
procedure TForm1.Button1Click(Sender: TObject);
var
  MyObject  : IUnknown;
  MySLink   : IShellLink;
  MyPFile   : IPersistFile;
begin
  MyObject := CreateComObject(CLSID_ShellLink);
  MySLink := MyObject as IShellLink;
  MyPFile := MyObject as IPersistFile;
  with MySLink do begin
    SetPath('myfile.exe');
    SetWorkingDirectory(Pchar('c:\'));
  end;
  MyPFile.Save(PWChar(widestring('c:\winnt\profile\xx.lnk')),False);
end;

menxin
0
 
men xinCEOCommented:
Oh.sorry,Madshi,we have a same way...
;-)

menxin
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
traustiAuthor Commented:
I get error on IShellLink
0
 
MadshiCommented:
menxin...  No problem...

trausti, have you added the nessecary units to your uses clause? Look at menxin's answer...

Regards, Madshi.
0
 
traustiAuthor Commented:
Thanks!!! to all
0
 
men xinCEOCommented:
trausti :
use shlobj

Ishelllink is in shlobj unit

menxin
0
 
traustiAuthor Commented:
Thanks!!! to all
0
 
traustiAuthor Commented:
Sorry!!!

What if i want a folder like "accessories" ?
0
 
traustiAuthor Commented:
Sorry!!!

What if i want a folder like "accessories" ?
0
 
men xinCEOCommented:
trausti:

no problem!

you can find the "programs" in

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer].programs!

Then....

menxin
0
 
traustiAuthor Commented:
Then What, do you have code for button click?
0
 
traustiAuthor Commented:
Then What, do you have code for button click?
0
 
men xinCEOCommented:
trausti:
Sure!

use registry;


var MyReg:TRegIniFile;
begin
  MyReg := TRegIniFile.Create(
    'Software\MicroSoft\Windows\CurrentVersion\Explorer');
  showmessage(MyReg.ReadString('Shell Folders','Programs',''));//this is you want
end;

menxin
0
 
traustiAuthor Commented:
How about if i want to set this link to accessories or make a new folder?
0
 
traustiAuthor Commented:
Sorry i write again the same code, your answer is great
0
 
traustiAuthor Commented:
What is that!!!

I mean i want to make shortcut on the computer with new folder
e.g

Start Menu - Programs - MyFolder - The New Shortcut
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 10
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now