我已经安装了程序。但是,如果我尝试再次安装它,它将安装并替换该程序。
我看到了这个问题Inno Setup-如果计算机上已经安装了应用程序,如何在安装时显示通知消息?
是否可以创建某个注册表项,以便对其进行检查并阻止新安装?在此问题中,有一些相关信息:Inno setup-如果未安装其他程序,则跳过安装。
您不需要创建任何注册表项。安装程序已经为卸载程序创建了一个注册表项。您可以检查一下。您所指的问题答案使用相同的键。但是您不需要进行版本检查。只是检查一个存在。另外,您应同时检查HKEY_LOCAL_MACHINE
和HKEY_CURRENT_USER
:
#define AppId "myapp"
[Setup]
AppId={#AppId}
[Code]
function InitializeSetup(): Boolean;
begin
Result := True;
if RegKeyExists(HKEY_LOCAL_MACHINE,
'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#AppId}_is1') or
RegKeyExists(HKEY_CURRENT_USER,
'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#AppId}_is1') then
begin
MsgBox('The application is installed already.', mbInformation, MB_OK);
Result := False;
end;
end;
Run Code Online (Sandbox Code Playgroud)