关注一下调用的方法!
下面创建快捷方式的方法:
定义好需要创建的位置
Folder: array[0..3] of string = ('Desktop', 'Start Menu', 'Programs', 'AppData');
函数如下:
//创建快捷方式
Procedure SetLink(FolderNo: Integer; ACmdFile, Parameter, LinkName: string);
// FolderNo 位置
var
MyObject : Iunknown;
MySLink : IShellLink;
MyPFile : IPersistFile;
FileName : string;
Directory : string;
WFileName : WideString;
MyReg : TRegIniFile;
begin
MyObject := CreateComObject(CLSID_ShellLink);
MySLink := MyObject as IShellLink;
MyPFile := MyObject as IPersistFile;
FileName := ACmdFile;
with MySLink do
begin
SetArguments(Pchar(Parameter));
SetPath(Pchar(FileName));
SetWorkingDirectory(Pchar(ExtractFilePath(FileName)));
end;
MyReg := TRegIniFile.Create(
'Software/MicroSoft/Windows/CurrentVersion/Explorer');
//防止异常,出现异常时将快捷方式创建在桌面处。
if ((FolderNo < 0) or (FolderNo > 3)) then FolderNo := 0;
if FolderNo <> 3 then
Directory := MyReg.ReadString('Shell Folders', Folder[FolderNo],'')
else
Directory := MyReg.ReadString('Shell Folders', Folder[FolderNo],'')
+ '/Microsoft/Internet Explorer/Quick Launch';
//CreateDir(Directory);
WFileName := Directory + '/' + LinkName + '.lnk';
MyPFile.Save(PWChar(WFileName), False);
MyReg.Free;
end;
这个函数的唯一缺点是只能够在桌面、开始菜单、程序、快速启动四个地方常见快捷方式,其他地方无法创建。