Registry Script Doesn’t Work

Hey, Scripting Guy! Question

Hey, Scripting Guy! I tried writing a script to read data from the registry, but I keep getting this error:

Error Screenshot


Do you have any idea what's wrong? I'm running Windows XP Professional, Service Pack 1, and this is the code I'm using:

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set oReg=GetObject("winmgmts:\\" &_

strComputer & "\root\cimV2:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon"

strValueName = "UIHost"

oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,_


Wscript.Echo "The Windows logon UI host is: " & strValue

-- LW, Omaha, NE

SpacerHey, Scripting Guy! AnswerScript Center

Hey, LW. The error you are getting (80041010) means that the specified class (in this case, root\cimv2:StdRegProv) is invalid; in other words, there's no such class. How could that be? Well, believe it or not, there's a simple reason for this: there really is no such class as root\cimv2:stdRegProv. Instead, the standard registry provider (stdRegprov) is actually found in root\default, not, in root\cimv2. Change your code to look like this, and you should be fine:

Set oReg=GetObject("winmgmts:\\" &_
strComputer & "\root\default:StdRegProv")

By the way, how did we know that error number 80041010 meant that you referenced an invalid class? Easy: we just looked up the error number in the WMI SDK.

Comments (3)

  1. very helpful. thanks. WMI can be a bit tricky

  2. AS says:

    The page for "StdRegProv class" [] says:

    "StdRegProv is preinstalled in the WMI namespaces rootdefault and rootcimv2."

    so the error doesn’t happen with cimv2.

    The "StdRegProv class" page also has this code as example code (with slight changes).

Skip to main content