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
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