NSIS - 检查是否存在注册表项值

use*_*892 7 nsis

如果存在注册表值,我需要检查.我怎样才能做到这一点?

我的第一个方法:

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}
Run Code Online (Sandbox Code Playgroud)

但是当价值不存在时,这也有效.我猜,因为"不存在",空字符串的处理方式相同.

使用Registry.nsh我这样做:

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

        ${IF} $var2 == "REG_SZ"
Run Code Online (Sandbox Code Playgroud)

但是我收到错误,因为registry.nsh中的Pop $ {_ STRING}不起作用.

欢迎提出帮助和建议!

Fra*_*o R 12

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

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}
Run Code Online (Sandbox Code Playgroud)

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