none
Reading Remote Registry using VB.Net RRS feed

  • Question

  • Hi All,

    I want read the below remote registry using VB.Net.
    "SOFTWARE\Microsoft\Windows\CurrentVersion\Install er\UserData\S-1-5-18\Products". I am using the below code but it is not giving any values.

     

    Dim strComputerName As String = "192.168.91.36"
    Dim strSubKeyName, strStringValue, strValueName, strValue   As String
    Dim strKeyPath As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
    Dim objManagementScope As ManagementScope
    Dim objManagementClass As ManagementClass
    Dim objManagementBaseObject As ManagementBaseObject
    Dim strkey, myKey, myValue As String
    Dim aSubKeys() As String
    objManagementScope = New ManagementScope
    objManagementScope.Path.Server = strComputerName
    objManagementScope.Path.NamespacePath =
    "root\default"
    objManagementScope.Options.EnablePrivileges = True
    objManagementScope.Options.Impersonation = ImpersonationLevel.Impersonate
    objManagementScope.Connect()

    objManagementClass =
    New ManagementClass("stdRegProv")
    objManagementClass.Scope = objManagementScope
    objManagementBaseObject = objManagementClass.GetMethodParameters(
    "EnumKey")
    objManagementBaseObject.SetPropertyValue(
    "hDefKey", CType("&H" & Hex(RegistryHive.LocalMachine), Long))
    objManagementBaseObject.SetPropertyValue(
    "sSubKeyName", strKeyPath)
    aSubKeys =
    CType(objManagementClass.InvokeMethod("EnumKey", objManagementBaseObject, Nothing).Properties.Item"sNames").Value, String())
    For Each strkey In aSubKeys
    myKey = strkey
    objManagementBaseObject = objManagementClass.GetMethodParameters(
    "GetStringValue")
    objManagementBaseObject.SetPropertyValue(
    "hDefKey", CType("&H" & Hex(RegistryHive.LocalMachine), Long))
    objManagementBaseObject.SetPropertyValue(
    "sSubKeyName", strKeyPath & strkey)
    objManagementBaseObject.SetPropertyValue(
    "sValueName", "DisplayName")
    objManagementBaseObject = objManagementClass.InvokeMethod(
    "GetStringValue", objManagementBaseObject, Nothing)
    myValue = objManagementBaseObject(
    "sValue")
    If Not myValue = "" Then
    TextBox1.Text &= myValue & ControlChars.NewLine
    End If
    NextPlease anyone help me.

    Thanks

    Arul

    Tuesday, April 21, 2009 7:18 AM