您好:下面代码解决您的问题:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Registry, ActiveX, ShlObj, ComObj, StdCtrls;
type
ShortcutType = (_DESKTOP, _QUICKLAUNCH, _SENDTO, _STARTMENU, _PROGRAMS);
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure CreateShortcut(SourceFileName: string; Location: ShortcutType; SubDirectory: string);
implementation
{$R *.dfm}
procedure CreateShortcut(SourceFileName: string; Location: ShortcutType; SubDirectory: string);
var
MyObject: IUnknown;
MySLink: IShellLink;
MyPFile: IPersistFile;
Directory, LinkName, TempStr: 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('Software/MicroSoft/Windows/CurrentVersion/Explorer');
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', '');
_PROGRAMS: Directory := MyReg.ReadString('Shell Folders', 'Programs', '');
_QUICKLAUNCH:
begin
QuickLaunchReg := TRegIniFile.Create('Software/MicroSoft/Windows/CurrentVersion/GrpConv');
try
Directory := QuickLaunchReg.ReadString('MapGroups', 'Quick Launch', '');
finally
QuickLaunchReg.Free;
end;
end;
end;
TempStr := Directory;
if Location = _PROGRAMS then Directory := Directory + '/' + SubDirectory;
if (Location = _PROGRAMS) and (TempStr <> Directory) then
if not DirectoryExists(Directory) then
if not ForceDirectories(Directory) then Directory := TempStr;
WFileName := Directory + '/' + LinkName;
MyPFile.Save(PWChar(WFileName), False);
finally
MyReg.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//CreateShortcut('C:/VipProgram/VipBrowserWeb_OCR/VipBrowser.exe',_STARTMENU,'');
//CreateShortcut('C:/VipProgram/VipBrowserWeb_OCR/VipBrowser.exe',_DESKTOP,'');
//CreateShortcut('C:/VipProgram/VipBrowserWeb_OCR/VipBrowser.exe',_SENDTO,'');
/////////您所需要的!!!!!!!!!!!!!!!!!!
//CreateShortcut('C:/VipProgram/VipBrowserWeb_OCR/VipBrowser.exe',_QUICKLAUNCH,'');
CreateShortcut('C:/VipProgram/VipBrowserWeb_OCR/VipBrowser.exe', _PROGRAMS, 'Folder/SubFolder');
end;
end.