WMI - Executing a method to read registry - Going Crazy!

B

Bmack500

Hello, and thanks in advance. I have the below code which keeps
returning "1" as the result. It's never successful, and I don't know
what I'm doing wrong. I know that when I get to objManagementClass &
objManagmeentBaseObject, the VB debugger says "can't read value" on all
lines. Bu tI can read the objPath, and the scope just fine.


Dim strStringValue As String = ""

'Dim strValue As String
Dim objManagementScope As ManagementScope
Dim objManagementClass As ManagementClass
Dim objManagementBaseObject As ManagementBaseObject
Dim objPath As ManagementPath

sSubKey = sSubKey.Trim
strValue = strValue.Trim

If (sSubKey.Length > 0) Then
'Connect to the specified computer registry
objPath = New ManagementPath
objPath.Server = "SERVERNAME(WIN2003)"
objPath.NamespacePath = "root\default"
objPath.ClassName = "stdRegProv"

objManagementScope = New ManagementScope(objPath)
objManagementScope.Options.EnablePrivileges = True
objManagementScope.Options.Impersonation =
ImpersonationLevel.Impersonate
objManagementScope.Connect()


'Retrieve the required string value from the registry

If objManagementScope.IsConnected Then
objManagementClass = New ManagementClass(objPath)
objManagementClass.Scope = objManagementScope
objManagementBaseObject =
objManagementClass.GetMethodParameters("GetStringValue")
objManagementBaseObject.SetPropertyValue("sSubKeyName",
sSubKey)
objManagementBaseObject.SetPropertyValue("sValueName",
strValue)
objManagementBaseObject =
objManagementClass.InvokeMethod("GetStringValue",
objManagementBaseObject, Nothing)
strReturn =
objManagementBaseObject.Properties.Item("ReturnValue").Value.ToString()
If strReturn = "0" Then
strResult =
CType(objManagementBaseObject.Properties.Item("sValue").Value, String)
Else
strReturn =
objManagementBaseObject.Properties.Item("ReturnValue").Value.ToString
End If
'objManagementclass.
End If
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top