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,_
strValueName,strValue
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.

0 comments

Comments are closed. Login to edit/delete your existing comments