如果想执行快捷方式: shellexecute(handle,'open','start.exe','c:\windows\desktop\aaa.lnk','',sw_hide); 如果想创建快捷方式 function CreateLinkFile(const info:LINK_FILE_INFO;const DestFileName:string=''):boolean; var anobj:IUnknown; shlink:IShellLink; pFile:IPersistFile; wFileName:widestring; begin wFileName:=destfilename; anobj:=CreateComObject(CLSID_SHELLLINK); shlink:=anobj as IShellLink; pFile:=anobj as IPersistFile; 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); if DestFileName='' then wFileName:=ChangeFileExt(info.FileName,'lnk'); result:=succeeded(pFile.Save(pwchar(wFileName),false)); end;
如果是想得到更多的Link文件的信息 function LinkFileInfo(const lnkFileName:string;var info:LINK_FILE_INFO;const bSet:boolean):boolean; var hr:hresult; psl:IShelllink; wfd:win32_find_data; ppf:IPersistFile; lpw:pwidechar; buf:pwidechar; begin result:=false; getmem(buf,MAX_PATH); try if SUCCEEDED(CoInitialize(nil)) then if (succeeded(cocreateinstance(clsid_shelllink,nil,clsctx_inproc_server,IID_IShellLinkA,psl))) then begin hr:=psl.QueryInterface(iPersistFile,ppf); if succeeded(hr) then begin lpw:=stringtowidechar(lnkfilename,buf,MAX_PATH); hr := ppf.Load(lpw, STGM_READ); if succeeded(hr) then begin hr := psl.Resolve(0, SLR_NO_UI); if succeeded(hr) then begin if bSet then begin psl.SetArguments(info.Arguments); psl.SetDescription(info.Description); psl.SetHotkey(info.HotKey); psl.SetIconLocation(info.IconLocation,info.IconIndex); psl.SetIDList(info.ItemIDList); psl.SetPath(info.FileName); psl.SetShowCmd(info.ShowState); psl.SetRelativePath(info.RelativePath,0); psl.SetWorkingDirectory(info.WorkDirectory); if succeeded(psl.Resolve(0,SLR_UPDATE)) then result:=true; end else begin psl.GetPath(info.FileName,MAX_PATH, wfd,SLGP_SHORTPATH ); psl.GetIconLocation(info.IconLocation,MAX_PATH,info.IconIndex); psl.GetWorkingDirectory(info.WorkDirectory,MAX_PATH); psl.GetDescription(info.Description,CCH_MAXNAME); psl.GetArguments(info.Arguments,MAX_PATH); psl.GetHotkey(info.HotKey); psl.GetIDList(info.ItemIDList); psl.GetShowCmd(info.ShowState); result:=true; end; end; end; end; end; finally freemem(buf); end; end;
对于楼上所说的我的电脑,网上邻居等,可以通过下面两个函数访问: var vItemIDList: PItemIDList; vBuffer: array[0..MAX_PATH] of Char; begin SHGetSpecialFolderLocation(0, mFolder, vItemIDList); SHGetPathFromIDList(vItemIDList, vBuffer); //转换成文件系统的路径 Result := vBuffer; end;
你的可以用写字版打开一个快捷方式的文件。
里面是有指向的文件路径和文件名
所以只要用FileOpen打开*.lnk,读出相应的目标就行了。
桌面上的和别的地方的是一样的。
不过有一点,桌面上的“我的电脑”“网上邻居”等不是快捷方式。
等会回去我给你 在我电脑里
我一直在研究不知道这是什么玩意儿??不知有哪位高手知道??
shellexecute(handle,'open','start.exe','c:\windows\desktop\aaa.lnk','',sw_hide);
如果想创建快捷方式
function CreateLinkFile(const info:LINK_FILE_INFO;const DestFileName:string=''):boolean;
var
anobj:IUnknown;
shlink:IShellLink;
pFile:IPersistFile;
wFileName:widestring;
begin
wFileName:=destfilename;
anobj:=CreateComObject(CLSID_SHELLLINK);
shlink:=anobj as IShellLink;
pFile:=anobj as IPersistFile;
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);
if DestFileName='' then
wFileName:=ChangeFileExt(info.FileName,'lnk');
result:=succeeded(pFile.Save(pwchar(wFileName),false));
end;
function LinkFileInfo(const lnkFileName:string;var info:LINK_FILE_INFO;const bSet:boolean):boolean;
var
hr:hresult;
psl:IShelllink;
wfd:win32_find_data;
ppf:IPersistFile;
lpw:pwidechar;
buf:pwidechar;
begin
result:=false;
getmem(buf,MAX_PATH);
try
if SUCCEEDED(CoInitialize(nil)) then
if (succeeded(cocreateinstance(clsid_shelllink,nil,clsctx_inproc_server,IID_IShellLinkA,psl))) then
begin
hr:=psl.QueryInterface(iPersistFile,ppf);
if succeeded(hr) then
begin
lpw:=stringtowidechar(lnkfilename,buf,MAX_PATH);
hr := ppf.Load(lpw, STGM_READ);
if succeeded(hr) then
begin
hr := psl.Resolve(0, SLR_NO_UI);
if succeeded(hr) then
begin
if bSet then
begin
psl.SetArguments(info.Arguments);
psl.SetDescription(info.Description);
psl.SetHotkey(info.HotKey);
psl.SetIconLocation(info.IconLocation,info.IconIndex);
psl.SetIDList(info.ItemIDList);
psl.SetPath(info.FileName);
psl.SetShowCmd(info.ShowState);
psl.SetRelativePath(info.RelativePath,0);
psl.SetWorkingDirectory(info.WorkDirectory);
if succeeded(psl.Resolve(0,SLR_UPDATE)) then
result:=true;
end
else
begin
psl.GetPath(info.FileName,MAX_PATH, wfd,SLGP_SHORTPATH );
psl.GetIconLocation(info.IconLocation,MAX_PATH,info.IconIndex);
psl.GetWorkingDirectory(info.WorkDirectory,MAX_PATH);
psl.GetDescription(info.Description,CCH_MAXNAME);
psl.GetArguments(info.Arguments,MAX_PATH);
psl.GetHotkey(info.HotKey);
psl.GetIDList(info.ItemIDList);
psl.GetShowCmd(info.ShowState);
result:=true;
end;
end;
end;
end;
end;
finally
freemem(buf);
end;
end;
var
vItemIDList: PItemIDList;
vBuffer: array[0..MAX_PATH] of Char;
begin
SHGetSpecialFolderLocation(0, mFolder, vItemIDList);
SHGetPathFromIDList(vItemIDList, vBuffer); //转换成文件系统的路径
Result := vBuffer;
end;