Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

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
add comment

1 Answer

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")
p_shell.RegRead("HKEY_USERS\S-1-5-19\Console\HistoryBufferSize")
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 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 9:31
add comment

Your Answer

 
discard

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.