Inno Setup 无法在 Windows 10 中创建桌面图标

5

我有一个最新版本的inno setup安装文件。它可以在Windows XP到Windows 8上编译和正常运行,但在Windows 10上创建桌面图标时会出现以下错误:

IPersistFile::Save 失败; 错误代码为0x80070002。

以下是我在安装文件中创建图标的方式:

[Icons]
Name: "{userdesktop}\Forex Tester 4"; Filename: "{app}\ForexTester4.exe"; Tasks: desktopicon

安装日志文件的一部分:

2019-02-01 12:50:46.376   -- Icon entry --
2019-02-01 12:50:46.376   Dest filename: C:\Users\Mike\Desktop\Forex Tester 4.lnk
2019-02-01 12:50:46.376   Creating the icon.
2019-02-01 12:50:46.376   Exception message:
2019-02-01 12:50:46.376   Message box (OK):
                          IPersistFile::Save failed; code 0x80070002.
                          The system cannot find the file specified.
2019-02-01 12:50:59.066   User chose OK.

这个文件夹存在,我可以手动在其中创建文件。但是Inno Setup无法完成此操作...除了桌面图标外,所有其他图标都没有问题。

有什么想法吗?


似乎Windows Defender或防病毒软件(如Bitdefender等)中的“受控文件夹访问”/“受保护文件夹”功能已开启。 - RobeN
是的,看起来就是这个问题(Defender 中的受保护文件夹)。你知道如何避免这种情况吗?因为所有将此选项设置为开启的用户在安装软件时,当安装程序创建快捷方式时都会收到错误消息。 - Mike K.
我通过右键单击安装程序并选择“以管理员身份安装”来规避了这个问题,但这可能不是一个好主意。 - Piovezan
2个回答

0

0

我在Windows 7和Windows 10上遇到了同样的错误,因为我试图创建指向尚不存在的文件的快捷方式。

[Icons]
; Create icons for the app
Name: "{group}\{#AppName}"; \
    Filename: "{app}\{#AppName}.lnk"; \
    BeforeInstall: CreateAppRunLink();
Name: "{commondesktop}\{#AppName}"; \
    Filename: "{app}\{#AppName}.lnk"; \
    Tasks: desktopicon;

所以在创建图标之前,我必须确保文件“{app}{#AppName}.lnk”存在: 这部分代码放到[Code]节中:

procedure CreateAppRunLink();
var
    Filename: string;
    Description: string;
    ShortcutTo: string;
    Parameters: string;
    WorkingDir: string;
    IconFilename: string;
begin
    Filename := ExpandConstant('{app}\MyApp.lnk');
    Description := 'Description';
    ShortcutTo := 'Full path to file that will be run (MyApp.exe)';
    Parameters := 'parameters if any';
    WorkingDir := ExpandConstant('{app}');
    IconFilename := ExpandConstant('{app}') + '\icon.ico';

    CreateShellLink(Filename, Description, ShortcutTo, Parameters, WorkingDir, 
        IconFilename, 0, SW_HIDE);
end;

CreateAppRunLink将在从[Files]部分提取任何文件后被调用,以确保我们的文件就位。
希望这能有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接