Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Executing the following VBScript on our Windows Server 2003

Set p_shell = CreateObject("WScript.Shell")

yields the following error

C:\Documents and Settings\Administrator\Desktop>cscript test.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\Documents and Settings\Administrator\Desktop\test.vbs(2, 1) WshShell.RegRead:
 Unable to open registry key "HKEY_USERS\S-1-5-19\" for reading.

although the user (Administrator) definitely has the necessary permissions. Reading the key directly from the command line works:

C:\Documents and Settings\Administrator\Desktop>reg query HKEY_USERS\S-1-5-19\ /ve

    (Default)    REG_SZ    (value not set)

and the permissions (as shown by regedit) are default: Full Control (LOCAL SERVICE, SYSTEM, Administrators), Read (RESTRICTED).

Why does the VBScript fail to read the default value of the key? Executing the same script (elevated) on a Vista machine works fine.

(I know that this script serves no useful purpose -- it's a minimal example to demonstrate the problem.)

share|improve this question
Is your VBScript code running in the correct user context? – user3914 Oct 21 '09 at 9:19
It's running in a command-line window of the Administrator, so it should be in the correct context, right? – Heinzi Oct 21 '09 at 9:29
up vote 1 down vote accepted

I get that error unless I put a specific registry key in the read command

Set p_shell = CreateObject("WScript.Shell")
share|improve this answer
Thanks, that sounds like a good workaround! (I need the RegRead only to check if the user has admin permissions, see for details.) Is there some specific value which is guaranteed to exist on every system (>= W2k3)? Still, I'm curious why the original RegRead doesn't work... – Heinzi Oct 21 '09 at 9:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.