在卸载过程中删除注册表项(不是由安装程序创建的)(Inno Setup)

Remove registry entry (which is not created by installer) during uninstallation (Inno Setup)

来自Inno Setup Help

dontcreatekey

When this flag is specified, Setup will not attempt to create the key or any value if the key did not already exist on the user's system. No error message is displayed if the key does not exist.

Typically this flag is used in combination with the uninsdeletekey flag, for deleting keys during uninstallation but not creating them during installation.

我的程序在当前用户自动启动部分下创建了一个注册表值(string 类型),但前提是用户从设置屏幕明确这样做。

我希望卸载程序清除该条目,因此我将以下内容添加到我的 Inno Setup 项目中:

[Registry]
Root: HKCU; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "this_is_a_test"; Flags: dontcreatekey uninsdeletevalue

但这似乎不起作用。我觉得 dontcreatekey 标志仅适用于 "keys"¹ 而不适用于 "values"。如果可以,我该如何实现?

(1) 假设 "key" 将是 "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"(在安装之前将始终存在),并且 "value" 将是类型 string 的条目驻留在该密钥中。

使用 ValueType: none 或完全省略 ValueType 参数:

If none (the default setting) is specified, Setup will create the key but not a value. In this case the ValueName and ValueData parameters are ignored.

不过请注意,文档并不完全正确。当与 uninsdeletevalue 标志组合时,ValueName 不会被忽略。

[Registry]
Root: HKCU; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; \
    ValueType: none; ValueName: "this_is_a_test"; Flags: dontcreatekey uninsdeletevalue