NSIS - 检查注册表项值是否存在 [英] NSIS - check if registry key value exists

查看:58
本文介绍了NSIS - 检查注册表项值是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查注册表值是否存在.我该怎么做?

I need to check, if a registry value exists. How can I do that?

我的第一种方法:

ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports" "NUL:"
        ${IF} $0 == ""
              MESSAGEBOX MB_OK "NUL exists"
        ${ELSE}
               WriteRegStr HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports" "NUL:" ""
        ${ENDIF}

但这也适用,当值不存在时.我猜,因为不存在"和空字符串的处理方式相同.

But this also works, when the value doesn’t exist. I guess, because "doesn’t exist" and empty string are handled the same way.

使用 Registry.nsh 我是这样做的:

With Registry.nsh I did it like this:

${registry::Read} "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports" "NUL:" $var1 $var2

        ${IF} $var2 == "REG_SZ"

但我收到一个错误,因为 registry.nsh 中的 Pop ${_STRING} 不起作用.

But I get an error, because the Pop ${_STRING} in the registry.nsh doesn’t work.

欢迎帮助和建议!

推荐答案

阅读后应该检查错误标志:

You should check the error flag after reading:

ClearErrors
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports" "NUL:"
${If} ${Errors}
  MessageBox MB_OK "Value not found"
${Else}
  ${IF} $0 == ""
              MESSAGEBOX MB_OK "NUL exists and it's empty"
        ${ELSE}
               WriteRegStr HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports" "NUL:" ""
        ${ENDIF}
${EndIf}

此外,在尝试阅读之前,您可能会对 EnumRegValue 感兴趣.

Also, you may be interested in EnumRegValue before trying to read it.

这篇关于NSIS - 检查注册表项值是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆