在桌面上自动创建快捷方式

usesShellAPI,ShlObj,ActiveX,ComObj;

const
CCH_MAXNAME
=255;
LNK_RUN_MIN
=7;
LNK_RUN_MAX
=3;
LNK_RUN_NORMAL
=1;
type
LINK_FILE_INFO
=record
FileName
:array[0..MAX_PATH]ofchar;
WorkDirectory
:array[0..MAX_PATH]ofchar;
IconLocation
:array[0..MAX_PATH]ofchar;
IconIndex
:integer;
Arguments
:array[0..MAX_PATH]ofchar;
Description
:array[0..CCH_MAXNAME]ofchar;
ItemIDList
:PItemIDList;
RelativePath
:array[0..255]ofchar;
ShowState
:integer;
HotKey
:word;
end;

functionCreateLinkFile(constinfo
:LINK_FILE_INFO;constDestFileName:string=''):boolean;
var
anobj
:IUnknown;
shlink
:IShellLink;
pFile
:IPersistFile;
wFileName
:widestring;
begin
wFileName
:=destfilename;
anobj
:=CreateComObject(CLSID_SHELLLINK);
shlink
:=anobjasIShellLink;
pFile
:=anobjasIPersistFile;
shlink
.SetPath(info.FileName);
shlink
.SetWorkingDirectory(info.WorkDirectory);
shlink
.SetDescription(info.Description);
shlink
.SetArguments(info.Arguments);
shlink
.SetIconLocation(info.IconLocation,info.IconIndex);
shlink
.SetHotkey(info.HotKey);
shlink
.SetShowCmd(info.ShowState);
shlink
.SetRelativePath(info.RelativePath,0);
ifDestFileName=''then
wFileName
:=ChangeFileExt(info.FileName,'lnk');
result
:=succeeded(pFile.Save(pwchar(wFileName),false));
end;
procedureTForm1.Button1Click(Sender:TObject);
var
rLnk:LINK_FILE_INFO;
pidl:pItemIDList;
pDesktop:
string;
begin
rLnk.FileName:
='C:ProgramFilesInternetExplorerIEXPLORE.EXE';
rLnk.WorkDirectory:
='C:ProgramFilesInternetExplorer';
rLnk.IconIndex:=0;

//取桌面路径
SetLength(pDesktop,255);
SHGetSpecialFolderLocation(Self.Handle,CSIDL_DESKTOP,pidl);
SHGetPathFromIDList(pidl,PChar(pDesktop));
SetLength(pDesktop,StrLen(PChar(pDesktop)));

CreateLinkFile(rLnk,pDesktop
+''+'I.lnk');
end;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值