FYI - Using WMI's StdRegProv to access the Registry 
Author Message
 FYI - Using WMI's StdRegProv to access the Registry

I just happened upon an interesting post in the microsoft.public.wbem newsgroup (i.e., WMI stuff for
those of you who don't hang out over there ;-) - Subject: "Accessing the registry with STDREGPROV".

I actually looked at the StdRegProv in an early release of WMI when you had to create and register a
MOF (whatever that is ;-) and decided it was too much trouble at the time.

But with WMI (version 1.5 at least, which is the current downloadable version), StdRegProv doesn't
require any of the original MOF-ing around.

You can do registry access very simply, including enumerating key and value names (things not
possible with WshShell registry methods).

The VBScript example below is from a VB example (in the WMI docs) that was trivial to adapt to
VBScript.  Unfortunately the code can't be adapted for JScript since it uses by reference method
arguments.  But I just ran this on a Win98 box and it works like a charm...

'=====
' StdRegProv
' http://www.*-*-*.com/
'=====

set objRegistry = GetObject("winmgmts://./root/default:StdRegProv")
'Assumes objRegistry is a valid StdRegProv object.

Const HKEY_LOCAL_MACHINE = &H80000002

Dim lRC '==> As Long
Dim sPath '==> As String
Dim sKeys() '==> As Variant

sPath = "SOFTWARE\Microsoft\Windows"

On Error Resume Next
lRC = objRegistry.EnumKey(HKEY_LOCAL_MACHINE, sPath, sKeys)

If (lRC <> 0) or (Err.Number <> 0) Then
    'An error occurred
End If

On Error GoTo 0

msgbox join(sKeys,vbCrLf)

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup...
--



Sun, 18 May 2003 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. FYI - Using WMI's StdRegProv to access the Registry

2. Using StdRegProv in WMI

3. WMI StdRegProv instead of RegWrite

4. WMI StdRegProv on Remote

5. Can WMI scripting be used to update registry?

6. multi-string registry change using WMI

7. Creating key registry with StdRegProv ?

8. FYI: WMI technical article

9. Writing to registry through WSH under credentials that don't have admin access

10. Using VBScript to access registry settings

11. trouble using StdRegProv in jscript

12. StdRegProv: error 6 when using Set/GetStringValue

 

 
Powered by phpBB® Forum Software