Retrieving Registry Keys with VBScript

Posted on 2007-07-24
Last Modified: 2007-12-19
As part of a larger script, I 'm trying to use vbscript to query the registry for the keys contained in HKEY_USERS.  Here is the relevent part of the script:

strComputer = "."
Set objRegistry = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")
Const HKEY_USERS = &H80000003
lngRtn = objRegistry.EnumKey(HKEY_USERS, "", arrRegKeys)
For Each strKey In arrRegKeys
Wscript.Echo "Key is " & strKey

On my Windows XP PC, it works fine, and gives the following results for strKey:
S-1-5-19     (HKEY_USERS\S-1-5-19)
S-1-5-19_Classes     (HKEY_USERS\S-1-5-19_Classes)
and so on

Hwoever on my Windows 2000 PC, it gives the following results for strKey:
AppEvents     (HKEY_USERS\.DEFAULT\AppEvents)
Control Panel     (HKEY_USERS\.DEFAULT\Control Panel)
Environment     (HKEY_USERS\.DEFAULT\Environment)
and so on.

In other words on my Windows 2000 PC, it's reading the keys from a level below where I want, and a level below where it reads them on my XP PC.

Can anyone explain what I'm doing wrong and help me correct the problem so that the script will run correctly on my Windows 2000 PC.
Question by:maike13
    LVL 22

    Accepted Solution


    Author Comment

    Wow thanks.  I'll give that a shot.  Should have known Microsoft were behind my problems :-)  This has been driving me crazy.  I don't suppose you have a copy of the hot fix?  It always seems to take Microsoft a couple of days to get around to mailing them.

    Author Comment

    Microsoft were much faster than previously and I now have the hotfix and it works.  The only snag is that, contrary to what MS say in the KB article,  it seems to require a re-boot.  This is a bit of a problem when distributing my code, but I'm hoping I can work around it by stopping and re-starting one of the Services.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
    Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now