Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 检查Inno安装程序中是否存在指向特定目标的快捷方式_Windows_Installation_Inno Setup_Shortcut_Pascalscript - Fatal编程技术网

Windows 检查Inno安装程序中是否存在指向特定目标的快捷方式

Windows 检查Inno安装程序中是否存在指向特定目标的快捷方式,windows,installation,inno-setup,shortcut,pascalscript,Windows,Installation,Inno Setup,Shortcut,Pascalscript,在我的Inno安装程序中,我需要确保文件夹中存在指向某个文件的快捷方式。快捷方式的名称是任意的,不受我的控制。我只知道它需要指向哪个文件。如果缺少快捷方式,我需要生成快捷方式。如果已存在,则不得再次创建 我猜想,在某种程度上,可以遍历相关文件夹中的所有快捷方式文件,并检查它们指向的文件。在对的回答中,提到了一个IShellLink接口,但我不知道如何在code部分提供它。(使用ShlObj;无法识别) 有人对我如何解决这个问题有什么建议吗?基于 和 已删除@TLama to的答复 需要Uni

在我的Inno安装程序中,我需要确保文件夹中存在指向某个文件的快捷方式。快捷方式的名称是任意的,不受我的控制。我只知道它需要指向哪个文件。如果缺少快捷方式,我需要生成快捷方式。如果已存在,则不得再次创建

我猜想,在某种程度上,可以遍历相关文件夹中的所有快捷方式文件,并检查它们指向的文件。在对的回答中,提到了一个
IShellLink
接口,但我不知道如何在
code
部分提供它。(
使用ShlObj;
无法识别)

有人对我如何解决这个问题有什么建议吗?

基于

  • 已删除@TLama to的答复
需要Unicode版本的Inno安装程序(Inno安装程序6的唯一版本)

const
最大路径=260;
STGM_READ=$00000000;
SLGP_短路径=1美元;
SLGP_RAWPATH=$4;
SLGP_相对优先级=8美元;
CLSID_ShellLink='{00021401-0000-0000-C000-0000000000 46}';
类型
TWin32FindDataW=记录
dwFileAttributes:DWORD;
ftCreationTime:TFileTime;
ftLastAccessTime:TFileTime;
ftLastWriteTime:TFileTime;
nFileSizeHigh:德沃德;
nFileSizeLow:德沃德;
dwReserved0:DWORD;
dwReserved1:DWORD;
cFileName:Char的数组[0..MAX_PATH-1];
cAlternateFileName:字符的数组[0..13];
结束;
IShellLinkW=接口(IUnknown)
“{000214F9-0000-0000-C000-0000000000 46}”
函数GetPath(pszFile:string;cchMaxPath:Integer;
var FindData:TWin32FindDataW;fFlags:DWORD):HRESULT;
程序Dummy2;
程序Dummy3;
函数GetDescription(pszName:string;cchMaxName:Integer):HRESULT;
函数SetDescription(pszName:string):HRESULT;
函数GetWorkingDirectory(pszDir:string;cchMaxPath:Integer):HRESULT;
函数SetWorkingDirectory(pszDir:string):HRESULT;
函数GetArguments(pszArgs:string;cchMaxPath:Integer):HRESULT;
函数SetArguments(pszArgs:string):HRESULT;
函数GetHotkey(var pHotkey:Word):HRESULT;
功能设置热键(wHotkey:Word):HRESULT;
函数GetShowCmd(out-piShowCmd:Integer):HRESULT;
函数SetShowCmd(iShowCmd:Integer):HRESULT;
函数GetIconLocation(pszIconPath:string;cchIconPath:Integer;
输出图标:整数):HRESULT;
函数SetIconLocation(pszIconPath:string;iIcon:Integer):HRESULT;
函数SetRelativePath(pszPathRel:string;dwReserved:DWORD):HRESULT;
函数解析(Wnd:HWND;fFlags:DWORD):HRESULT;
函数SetPath(pszFile:string):HRESULT;
结束;
IPersist=接口(IUnknown)
“{0000010C-0000-0000-C000-0000000000 46}”
函数GetClassID(var classID:TGUID):HRESULT;
结束;
IPersistFile=接口(IPersist)
“{0000010B-0000-0000-C000-0000000000 46}”
函数为dirty:HRESULT;
函数加载(pszFileName:string;dwMode:Longint):HRESULT;
函数保存(pszFileName:string;fRemember:BOOL):HRESULT;
函数SaveCompleted(pszFileName:string):HRESULT;
函数GetCurFile(out-pszFileName:string):HRESULT;
结束;
函数GetLinkFileTarget(常量文件名:string):string;
变量
FindData:TWin32FindDataW;
共同研究对象:IUnknown;
ShellLink:IShellLinkW;
PersistFile:IPersistFile;
开始
ComObject:=CreateComObject(StringToGuid(CLSID_ShellLink));
PersistFile:=IPersistFile(ComObject);
olcheck(PersistFile.Load(文件名,STGM_READ));
ShellLink:=IShellLinkW(共对象);
设置长度(结果,最大路径);
olcheck(ShellLink.GetPath(Result,MAX_PATH,FindData,SLGP_RAWPATH));
设置长度(结果,位置(#0,结果)-1);
结束;
过程IterateShortcuts(路径:string);
变量
FindRec:TFindRec;
ShortcutPath:string;
TargetPath:字符串;
开始
路径:=添加反斜杠(路径);
日志(格式('在[%s]中查找.lnk',[Path]);
如果FindFirst(路径+'*.lnk',FindRec),则
开始
尝试
重复
ShortcutPath:=Path+FindRec.Name;
TargetPath:=GetLinkFileTarget(ShortcutPath);
日志(格式('快捷方式[%s]的目标为[%s]”,[ShortcutPath,TargetPath]);
直到没有FindNext(FindRec);
最后
FindClose(FindRec);
结束;
结束;
结束;