Atalho
como Criar Atalho de minha aplicação independente da versão do Windows via Programação ?
Spider
Curtidas 0
Respostas
Márcio Dertônio
27/11/2003
Este exemplo é de como criar no desktop, no win98 funcionou bem, no xp estou testando, depois lhe dou uma posição.
uses ShlObj, ActiveX,ComObj, Registry;
Por último, crie uma procedure que faça o trabalho:
procedure CreateShortcut (FileName, Parameters, InitialDir, ShortcutName, ShortcutFolder : String);
var
MyObject : IUnknown;
MySLink : IShellLink;
MyPFile : IPersistFile;
Directory : String;
WFileName : WideString;
MyReg : TRegIniFile;
begin
MyObject := CreateComObject(CLSID_ShellLink);
MySLink := MyObject as IShellLink;
MyPFile := MyObject as IPersistFile;
with MySLink do
begin
SetArguments(Parameters);
SetPath(PChar(FileName));
SetWorkingDirectory(PChar(InitialDir));
end;
MyReg := TRegIniFile.Create(´Software\MicroSoft\Windows\CurrentVersion\Explorer´);
Directory := MyReg.ReadString (´Shell Folders´,´Desktop´,´´);
WFileName := Directory + ´\´ + ShortcutName + ´.lnk´;
MyPFile.Save (PWChar (WFileName), False);
MyReg.Free;
end;
uses ShlObj, ActiveX,ComObj, Registry;
Por último, crie uma procedure que faça o trabalho:
procedure CreateShortcut (FileName, Parameters, InitialDir, ShortcutName, ShortcutFolder : String);
var
MyObject : IUnknown;
MySLink : IShellLink;
MyPFile : IPersistFile;
Directory : String;
WFileName : WideString;
MyReg : TRegIniFile;
begin
MyObject := CreateComObject(CLSID_ShellLink);
MySLink := MyObject as IShellLink;
MyPFile := MyObject as IPersistFile;
with MySLink do
begin
SetArguments(Parameters);
SetPath(PChar(FileName));
SetWorkingDirectory(PChar(InitialDir));
end;
MyReg := TRegIniFile.Create(´Software\MicroSoft\Windows\CurrentVersion\Explorer´);
Directory := MyReg.ReadString (´Shell Folders´,´Desktop´,´´);
WFileName := Directory + ´\´ + ShortcutName + ´.lnk´;
MyPFile.Save (PWChar (WFileName), False);
MyReg.Free;
end;
GOSTEI 0