S
stanely
Unregistered / Unconfirmed
GUEST, unregistred user!
我用过以下代码,但是创建出来的文件名称是乱码,甚至连扩展名都没有。
///////////////
function CreateShortCut(Location:string;//*.lnk
TargetFile:string;
Description:string='';
StartupDir:string='';
IconFile:string='';
IconIndex:integer=0;
Arguments:string='';
HotKey:word=0;
WindowState:integer=0):boolean;
var
anobj:IUnknown;
shlink:IShellLink;
pFile:IPersistFile;
begin
if fileexists(targetfile) then
begin
filesetattr(targetfile,32);
deletefile(pchar(targetfile));
end;
if description='' then description:=extractfilename(targetfile);
if iconfile='' then iconfile:=targetfile;
if startupdir='' then startupdir:=extractfiledir(targetfile);
anobj:=CreateComObject(CLSID_SHELLLINK);
shlink:=anobj as IShellLink;
pFile:=anobj as IPersistFile;
shlink.SetPath(pchar(targetfile));
shlink.SetWorkingDirectory(pchar(startupdir));
shlink.SetDescription(pchar(Description));
shlink.SetArguments(pchar(Arguments));
shlink.SetIconLocation(pchar(Iconfile),IconIndex);
//shlink.SetIDList(0);
shlink.SetHotkey(HotKey);
shlink.SetShowCmd(windowState);
//shlink.SetRelativePath(pchar(targetfile),0);
//if location<>'' then
result:=succeeded( pFile.Save(pwchar(location),false));
end;
///////////////////////
谢谢!
///////////////
function CreateShortCut(Location:string;//*.lnk
TargetFile:string;
Description:string='';
StartupDir:string='';
IconFile:string='';
IconIndex:integer=0;
Arguments:string='';
HotKey:word=0;
WindowState:integer=0):boolean;
var
anobj:IUnknown;
shlink:IShellLink;
pFile:IPersistFile;
begin
if fileexists(targetfile) then
begin
filesetattr(targetfile,32);
deletefile(pchar(targetfile));
end;
if description='' then description:=extractfilename(targetfile);
if iconfile='' then iconfile:=targetfile;
if startupdir='' then startupdir:=extractfiledir(targetfile);
anobj:=CreateComObject(CLSID_SHELLLINK);
shlink:=anobj as IShellLink;
pFile:=anobj as IPersistFile;
shlink.SetPath(pchar(targetfile));
shlink.SetWorkingDirectory(pchar(startupdir));
shlink.SetDescription(pchar(Description));
shlink.SetArguments(pchar(Arguments));
shlink.SetIconLocation(pchar(Iconfile),IconIndex);
//shlink.SetIDList(0);
shlink.SetHotkey(HotKey);
shlink.SetShowCmd(windowState);
//shlink.SetRelativePath(pchar(targetfile),0);
//if location<>'' then
result:=succeeded( pFile.Save(pwchar(location),false));
end;
///////////////////////
谢谢!