Créer un raccourci dans le menu démarrer, sur le bureau

Uses Registry, ShlObj;

type
ShortcutType = (_DESKTOP, _QUICKLAUNCH, _SENDTO, _STARTMENU);


procedure CreateShortcut(SourceFileName: string; Location: ShortcutType; SubDirectory :
string);
var
MyObject : IUnknown;
MySLink : IShellLink;
MyPFile : IPersistFile;
Directory, LinkName : string;
WFileName : WideString;
MyReg, QuickLaunchReg : TRegIniFile;
begin
MyObject := CreateComObject(CLSID_ShellLink);
MySLink := MyObject as IShellLink;
MyPFile := MyObject as IPersistFile;
MySLink.SetPath(PChar(SourceFileName));
MyReg := TRegIniFile.Create('SoftwareMicroSoftWindowsCurrentVersionExplorer');
try
LinkName := ChangeFileExt(SourceFileName, '.lnk');
LinkName := ExtractFileName(LinkName);
case Location of
_DESKTOP : Directory := MyReg.ReadString('Shell Folders', 'Desktop', '');
_STARTMENU : Directory := MyReg.ReadString('Shell Folders', 'Start Menu', '');
_SENDTO : Directory := MyReg.ReadString('Shell Folders', 'SendTo', '');
_QUICKLAUNCH:
begin
QuickLaunchReg :=
TRegIniFile.Create('SoftwareMicroSoftWindowsCurrentVersionGrpConv');
try
Directory := QuickLaunchReg.ReadString('MapGroups', 'Quick Launch', '');
finally
QuickLaunchReg.Free;
end;
end;
end;
if Directory <> '' then
begin
if SubDirectory <> '' then
WFileName := Directory + ''+ SubDirectory +'' + LinkName
else
WFileName := Directory + '' + LinkName;
MyPFile.Save(PWChar(WFileName), False);
end;
finally
MyReg.Free;
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
//Create a Shortcut in the Startmenu, in the Directory
//Programs
CreateShortcut('c:YourProgram.exe',_STARTMENU,'Programs');

//Create a Shortcut on the Desktop
CreateShortcut('c:YourProgram.exe',_DESKTOP,'');
end;
Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour28/11/2001
VisualisationVu 930 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Systeme
Auteur de l'article
SwissDelphiCenter SwissDelphiCenter
connecté le 02/11/2011
329 articles dans la section
Contacter l'auteur