terça-feira, 16 de junho de 2009

Criando um atalho no desktop

//Coloque essas units na seção implementation :
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('SoftwareMicroSoftWindowsCurrentVersionExplorer');
Directory := MyReg.ReadString ('Shell Folders','Desktop','');
WFileName := Directory + '' + ShortcutName + '.lnk';
MyPFile.Save (PWChar (WFileName), False);
MyReg.Free;
end;

Nenhum comentário:

Postar um comentário