"Not Found" error in System.Management with GetDWORDValue Method

G

Guest

I am not sure what I am doing wrong .. I am simply looking to return a
registry key of type DWORD using System.Management and it errors out and
tells me it is not found .. I have to be able to pass credentials to the
remote maching so Win32.Registry key will not work

MY CODE

'Get schemaVersion from registry
Dim options As New ConnectionOptions
options.Username = userName
options.Password = password
Dim regServerName As String = serverName
Dim strStringValue As String
Dim strValue As String
Dim objManagementScope As ManagementScope
Dim objManagementClass As ManagementClass
Dim objManagementBaseObject As ManagementBaseObject

objManagementScope = New ManagementScope
objManagementScope.Path.Server = regServerName
objManagementScope.Path.NamespacePath = "root\default"
objManagementScope.Options.Username = userName
objManagementScope.Options.Password = password
objManagementScope.Connect()

'Retrieve the required string value from the registry
Dim intRegistryHive As RegistryHive = RegistryHive.LocalMachine
Dim strSubKeyName As String = "SOFTWARE\Microsoft\COM3\"
Dim strValueName As String = "CurrentSchemaVersion"

If objManagementScope.IsConnected Then
objManagementClass = New ManagementClass("StdRegProv")
objManagementClass.Scope = objManagementScope

Dim strRetVal As String
objManagementClass.Scope = objManagementScope

objManagementBaseObject =
objManagementClass.GetMethodParameters("GetDWORDValue")
objManagementBaseObject.SetPropertyValue("hDefKey", CType("&H" &
Hex(intRegistryHive), Long))
objManagementBaseObject.SetPropertyValue("sSubKeyName",
strSubKeyName)
objManagementBaseObject.SetPropertyValue("sValueName",
strValueName)

strRetVal =
CType(objManagementClass.InvokeMethod("GetDWORDValue",
objManagementBaseObject, Nothing).Properties.Item("lValue").Value, String)
End If

It errors out and I get a Not Found error .. yet I know that the value is
there because I looked in the registry and I can slightly modify the above
code to return the key value names using the EnumValues method ..

MODIFIED CODE

If objManagementScope.IsConnected Then
objManagementClass = New ManagementClass("StdRegProv")
objManagementClass.Scope = objManagementScope

Dim arrSubKeys As String()
Dim arrTypes As Integer()
objManagementClass.Scope = objManagementScope

objManagementBaseObject =
objManagementClass.GetMethodParameters("EnumValues")
objManagementBaseObject.SetPropertyValue("hDefKey", CType("&H" &
Hex(intRegistryHive), Long))
objManagementBaseObject.SetPropertyValue("sSubKeyName",
strSubKeyName)
'objManagementBaseObject.SetPropertyValue("sValueName",
strValueName)

arrSubKeys = objManagementClass.InvokeMethod("EnumValues",
objManagementBaseObject, Nothing).Properties.Item("sNames").Value
arrTypes = CType(objManagementClass.InvokeMethod("EnumValues",
objManagementBaseObject, Nothing).Properties.Item("Types").Value, Integer())
End If

This returns the CurrentSchemaVersion as the name and a type value of 4 so I
know I need to use the GetDWORDValue method to retrieve the value however it
errors out ??????
 

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