2

Executing the following VBScript on our Windows Server 2003

Set p_shell = CreateObject("WScript.Shell")
p_shell.RegRead("HKEY_USERS\S-1-5-19\")

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

HKEY_USERS\S-1-5-19
    (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.)

2
  • Is your VBScript code running in the correct user context?
    – user3914
    Oct 21, 2009 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, 2009 at 9:29

1 Answer 1

1

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

Set p_shell = CreateObject("WScript.Shell")
p_shell.RegRead("HKEY_USERS\S-1-5-19\Console\HistoryBufferSize")
1
  • Thanks, that sounds like a good workaround! (I need the RegRead only to check if the user has admin permissions, see stackoverflow.com/questions/1599567 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, 2009 at 9:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .