uses
comobj,activex,shlobj;
type //快捷方式位置
TLinkPlace=(lkDeskTop,//桌面
lkStartMenu,//开始菜单
lkProgram);//程序
var
LinkPlace:array [0..2] of integer=
(CSIDL_DESKTOPDIRECTORY,
CSIDL_STARTMENU,
CSIDL_PROGRAMS);
procedure CreateLink(LinkFile:WideString;LinkName:string;const Place:TLinkPlace);
var
lvs_FileName,lvs_StartupFilename:string;
lv
bject:IUnknown;
lvo_SLink:IShellLink;
lvo_PFile:IPersistFile;
lvo_PIDL : PItemIDList;
lvs_StartupDirectory : array[0..MAX_PATH] of Char;
lvs_LinkFilename : WideString;
begin
lvs_StartupFilename := LinkFile ;
lv
bject := CreateComObject(CLSID_ShellLink);
lvo_SLink := lv
bject as IShellLink;
lvo_PFile := lv
bject as IPersistFile;
lvo_SLink.SetPath(pChar(lvs_StartupFilename));
lvo_SLink.SetWorkingDirectory(PChar(ExtractFilePath(lvs_StartupFilename)));
SHGetSpecialFolderLocation(0, LinkPlace[Ord(Place)], lvo_PIDL);
SHGetPathFromIDList(lvo_PIDL, lvs_StartupDirectory);
lvs_FileName := '/'+LinkName+'.lnk';
lvs_LinkFilename := lvs_StartupDirectory + lvs_FileName;
lvo_PFile.Save(pWChar(lvs_LinkFilename),FALSE);
end;
调用:
CreateLink('程序名','快捷方式名称',lkDesktop);//在桌面上创建快捷方式
//放在启动里
procedure TForm1.WriteRegAutoRun(FileName:string);
var
Regf:TRegistry;
begin
Regf:=TRegistry.Create;
Regf.RootKey:=HKEY_LOCAL_MACHINE;
if Length(FileName)>0 then
try
RegF.OpenKey('SOFTWARE/Microsoft/Windows/CurrentVersion/Run',false);
RegF.WriteString('YourProgram',FileName);
except
end;
RegF.CloseKey;
RegF.Free;
end;