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.)

Heinzi
  • 2,138
  • 5
  • 30
  • 51
  • Is your VBScript code running in the correct user context? –  Oct 21 '09 at 09: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 09:29

1 Answers1

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")
Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148
  • Thanks, that sounds like a good workaround! (I need the RegRead only to check if the user has admin permissions, see http://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 '09 at 09:31