0

I already posted a similar question (NSIS - check if registry key value exists) and the solution to that question worked perfectly:

ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports" "NUL:"

And then:

${If} ${Errors}
#and so on

I do the same thing three more times in the script, reading different registry values and all attempts but the last one are successful:

ReadRegStr $3 HKLM "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\SomePrinter" "Name"

This always returns an error.

What should I do differently?

The first time I read a registry value, I use $0 to store the return vale. Then the second time $1 and then $2 and $3.

As I said, all work except for the last one. Does it have to do with the type of registry key I'm reading or should I use a different variable for the return value? I have tried other variables, but so far nothing has worked.

Thanks for help and tips!

Community
  • 1
  • 1
user3629892
  • 2,960
  • 9
  • 33
  • 64

1 Answers1

2

The problem with

ReadRegStr $3 HKLM "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers\SomePrinter" "Name"

is that you specify the root twice:

  • HKLM
  • HKEY_LOCAL_MACHINE\...

Remove the HKEY_LOCAL_MACHINE from the sub key name and it should be OK. If you need to access another part of the registry, change the 2 parameter of ReadRegStr as described in WriteRegExpandStr manual section:

  • HKCR for HKEY_CLASSES_ROOT
  • HKLM for HKEY_LOCAL_MACHINE
  • HKCU for HKEY_CURRENT_USER
  • HKU for HKEY_USERS
  • HKCC for HKEY_CURRENT_CONFIG
  • HKDD for HKEY_DYN_DATA
  • HKPD for HKEY_PERFORMANCE_DATA
  • SHCTX for SHELL_CONTEXT
Seki
  • 11,135
  • 7
  • 46
  • 70
  • it's incredible how you dont see those things sometimes. I query the registry 4 times in my script, 3 times I wrote it correctly and the 4th time I write the root twice... you'd think one would notice... Thanks! – user3629892 Jan 20 '15 at 09:45
  • You're welcome. We all miss things from time to time :o) If it helped, think about [accepting the answer](http://meta.stackoverflow.com/a/65088/173356) – Seki Jan 20 '15 at 10:13