在setup.exe安装期间,如果注册表中存在特定的密钥,我想中止安装。要实现这一点,我在安装盾牌项目中使用自定义操作调用install-script功能。 安装脚本代码是:
function MyFunction(hMSI)
// To Do: Declare local variables.
STRING szKey;
NUMBER nRootKey;
begin
// Set the root key to HKEY_LOCAL_MACHINE.
nRootKey = HKEY_LOCAL_MACHINE;
if (RegDBSetDefaultRoot (nRootKey) < 0) then
MessageBox ("First call to RegDBSetDefaultRoot failed.", SEVERE);
else
MessageBox ("Root key successfully set to HKEY_LOCAL_MACHINE.",
INFORMATION);
endif;
szKey = "SOFTWARE\\Test";
if (RegDBKeyExist (szKey)< 0) then
MessageBox ("Test is not present", SEVERE);
abort;
endif;
if (RegDBKeyExist (szKey)= 1) then
MessageBox ("Test is present", SEVERE);
abort;
endif;
// To Do: Write script that will be executed when MyFunction is called.
end;
每次我收到消息“测试不存在”,即使注册表中存在密钥“HKEY_LOCAL_MACHINE \ SOFTWARE \ Test”。
我认为我做了一些错误的脚本或遗漏了一些东西。 请帮忙。
https://community.flexerasoftware.com/showthread.php?139026-Check-if-a-registry-key-exists
答案 0 :(得分:2)
在您的问题中没有100%确认,但我会给出强烈的赔率:
如果这一切都是真的,那么问题是您已经创建了密钥HKEY_LOCAL_MACHINE \ SOFTWARE \ Test,但是您的代码正在检查HKEY_LOCAL_MACHINE \ SOFTWARE \ WOW6432Node \ Test,而不是registry redirector。要解决此问题,您应该执行以下操作之一:
请注意,如果此密钥是由您控制之外的软件创建的,则需要确保检查正确的位置。这将影响第一或第二颗子弹是否适合您的情况。 (如果密钥完全在您的控制之下,您还应该考虑它是否使用正确的位置,如果不是,则进行更改。)