none
Error accesing registry key RRS feed

  • Question

  • Hello,

    I have a script which tries to read a registry key from Windows 2008 R2 server. The key resides under HKLM\Software. I create by hand a new key that doesn't exist before (HKLM\Software\test), and I create a REG_SZ value (like 'config') with value 'aaa'. I try to read it with a regread and I get a 'invalid root key for HKLM\Software\test\config error message. 

    I get this error even if I do it with local admin, in an elevated cmd console. But in other servers, it works correctly. Even more, if I create the key under HKLM\System instead of HKLM\Software, it works perfectly.

    Which can be the problem that makes this fail?

    I'm completely blocked.

    Thanks

    Tuesday, November 25, 2014 3:24 PM

Answers

All replies

  • Which can be the problem that makes this fail?

    I'm completely blocked.


    It would help if you posted your script (to avoid guessing).
    Tuesday, November 25, 2014 3:29 PM
  • This is the script:

    Set WshShell = WScript.CreateObject("WScript.Shell")

    value = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Test\config")

    msgbox value

    This script finishes with a 'invalid root key' error message

    And I can guarantee that the key exists.

    Thanks.



    Tuesday, November 25, 2014 3:34 PM
  • You should definitely post your script and also validate credentials and rights on that registry key.
    Tuesday, November 25, 2014 3:35 PM
  • The script is posted yet.

    The permissions are the same than the ones under HKEY_LOCAL_MACHINE\System, but to avoid doubt, I have given Everyone group Full Control to that key. Also, I have to say that both in the server that works, and in the one that doesn't work, the UAC is completely disabled. And in both cases, I run the script with local administrator user, and with elevated cmd console.

    Thank you.

    Tuesday, November 25, 2014 3:39 PM
  • Also, I have to say that both in the server that works, and in the one that doesn't work, the UAC is completely disabled.

    Well that doesn't sound secure. I would recommend you post your script or at least the portion that's failing. Also I would open a console on the server in question and try to manually run the command you're trying to execute on that server. Hope this helps.
    Tuesday, November 25, 2014 3:45 PM
  • Tuesday, November 25, 2014 3:46 PM
  • This is the complete script:

    Set WshShell = WScript.CreateObject("WScript.Shell")

    value = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Test\config")

    msgbox value

    I open the console, elevated or not, and run the script. It gives the message 'invalid root key'.

    The same script, in the other server, works perfectly, even in a non elevated cmd console.

    Thanks

    Tuesday, November 25, 2014 3:51 PM
  • Apart from the security issues: Adding a backslash to "config" should solve the problem.
    • Proposed as answer by Mike Laughlin Tuesday, November 25, 2014 3:53 PM
    Tuesday, November 25, 2014 3:52 PM
  • I have added a backslash after config. The same result.

    I have tried with Getstringvalue method as pointed by Mike Lauglin. The error is 'invalid use of strValue, which I think it means that doesn't find the registry key.

    I'm going crazy, the scripts say that there isn't there a key in the registry, but that key is visible in regedit.

    Tuesday, November 25, 2014 4:06 PM
  • I'm going crazy, the scripts say that there isn't there a key in the registry, but that key is visible in regedit.

    In such cases it helps to vary the conditions, e.g. by running this variant on a machine that has Outlook installed:

    Set WshShell = WScript.CreateObject("WScript.Shell")
    value = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Clients\mail\")
    MsgBox value

    Tuesday, November 25, 2014 4:11 PM
  • I have found something that can put us on the clue.

    I have created a list of HKLM\Software subkeys running a script using the enumkeys method. And I have found something interesting:

    It has listed some of the keys under HKLM\Software, but not all of them. And it has listed some subkeys that are not under HKLM\Software, but under HKLM\Software\Wow6432Node. But again, not all the subkeys under Woe6432Node Subkeys are listed. And the Wow6432Node subkey itself under Software, is not listed.

    It seams that what you can see under regedit, is not the same that it can be viewed by the script.


    Tuesday, November 25, 2014 4:22 PM
  • 32/64 ???


    ¯\_(ツ)_/¯

    Tuesday, November 25, 2014 4:29 PM
  • I think so. The question now is how to solve it.
    Tuesday, November 25, 2014 4:31 PM
  • Set WshShell=CreateObject("WScript.Shell")
    MsgBox WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Test\config")

    if running from 64 bit.


    ¯\_(ツ)_/¯

    Tuesday, November 25, 2014 4:40 PM
  • Thanks for your help.

    Finally, the problem was the 32/64 bits version of regedit to create the keys, and the 32/64 bits version of wscript to execute the script. It's quite confusing.

    :-)

    Tuesday, November 25, 2014 4:50 PM
  • P.S. - OP's exact code works perfectly with no elevation.

    A key created under 64 bit is not visible to 32 bit sessions. A key created in 32 bit sessions is visible to 64 bit sessions.


    ¯\_(ツ)_/¯


    • Edited by jrv Tuesday, November 25, 2014 4:52 PM
    Tuesday, November 25, 2014 4:52 PM
  • Read the documentation, as it will really help to clarify all of this.

    Running 32-bit Applications

    The sections on the file system and registry reflectors are illuminating.


    -- Bill Stewart [Bill_Stewart]


    Tuesday, November 25, 2014 5:15 PM
    Moderator