简体   繁体   中英

NSIS FontReg, FontRegAdv and ReadRegStr + CurrentVersion

We're using NSIS to install fonts along with the rest of our stuff. The font installation isn't successful, and I've tracked it down (I think) to an issue with how the registry entries are generated.

Both FontReg and FontRegAdv have the following lines:

${Index}:
  ClearErrors
  ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
  IfErrors "${Index}-9x" "${Index}-NT"

"${Index}-NT:"
  StrCpy $R1 "Software\Microsoft\Windows NT\CurrentVersion\Fonts"
  goto "${Index}-GO"

"${Index}-9x:"
  StrCpy $R1 "Software\Microsoft\Windows\CurrentVersion\Fonts"
  goto "${Index}-GO"

We see the registry keys being created in

HKLM\Software\Microsoft\Windows\CurrentVersion\Fonts

which tells me that ReadRegStr is throwing an error (and so thinks this is a pre-NT-era registry). Interestingly, the correct value is returned by ReadRegStr (6.1 -- determined by adding a MessageBox).

This is on Windows 7 64-bit. We do see the correct parallel registry keys appearing in the Wow6432Node area. This is running with admin privileges. "SetRegView 64" doesn't change anything.

The documentation for ReadRegStr says that it only fails if the key isn't present; I have verified that the key is present. Why is ReadRegStr claiming to have failed, even when it returns a (correct) value?

I don't know where you got the idea that it only fails if the key is not present. The current docs say this:

The error flag will be set and $x will be set to an empty string ("") if the string is not present. If the value is present, but is of type REG_DWORD, it will be read and converted to a string and the error flag will be set.

This is almost 100% correct but if the value is of some other type it will also fail.

NSIS v3.0 beta behaves like this:

Return     | Error | Reason
-----------+-------+-------
"" (empty) | Yes   | Cannot open key for KEY_READ access
"" (empty) | Yes   | RegQueryValueEx failed
number     | Yes   | Type is REG_DWORD
"" (empty) | Yes   | Type is not REG_SZ and not REG_EXPAND_SZ
string     | No    | Value existed and is of type REG_SZ or REG_EXPAND_SZ

You could try replacing the IfErrors check with StrCmp "" $R0 "${Index}-9x" "${Index}-NT" or just remove the 9x parts if you don't support Windows 95/98/ME.

I cannot explain why it fails but still reads the correct string. Have you tried taking a look with Process Monitor ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM