VB.NET How to access remote registry users volatile

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CellnetixIT
    New Member
    • Feb 2010
    • 1

    VB.NET How to access remote registry users volatile

    I'm trying to return from a webpage, the remote HKCU\Volatile\C LIENTNAME

    Here's what I'm doing so far:

    Get the Machine Name via DNS - this bit works great:
    Code:
            Public Shared Function GetMachineName(ByVal sender As System.Web.UI.Control) As String
                Dim host As System.Net.IPHostEntry = Nothing
                Dim machinename As String = ""
    
                host = System.Net.Dns.GetHostEntry(sender.Page.Request.ServerVariables("REMOTE_ADDR"))
                machinename = host.HostName
    
                Return UCase(machinename).Replace(".CELLNETIX.LOCAL", "")
    
            End Function
    Then using that information, attempt to access the registry and pull the value:

    Code:
            Public Shared Function getClientName(Optional ByVal MachineName As String = "localhost") As String
                Dim strReturn As String = ""
    
                strReturn = regValue(RegistryHive.CurrentUser, "Volatile Environment", "CLIENTNAME", MachineName)
    
    
                Return strReturn
    Remote Registry Function
    Code:
            Public Shared Function regValue(ByVal hive As RegistryHive, _
                                            ByVal key As String, _
                                            ByVal ValueName As String, _
                                            Optional ByVal MachineName As String = "localhost", _
                                            Optional ByRef ErrInfo As String = "") As String
                Dim objParent As RegistryKey = Nothing
                Dim objSubkey As RegistryKey = Nothing
                Dim sAns As String = ""
    
                Select Case hive
                    Case RegistryHive.ClassesRoot
                        objParent = RegistryKey.OpenRemoteBaseKey(RegistryHive.ClassesRoot, MachineName)
                    Case RegistryHive.CurrentConfig
                        objParent = RegistryKey.OpenRemoteBaseKey(RegistryHive.CurrentConfig, MachineName)
                    Case RegistryHive.CurrentUser
                        objParent = RegistryKey.OpenRemoteBaseKey(RegistryHive.CurrentUser, MachineName)
                    Case RegistryHive.DynData
                        objParent = RegistryKey.OpenRemoteBaseKey(RegistryHive.DynData, MachineName)
                    Case RegistryHive.LocalMachine
                        objParent = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, MachineName)
                    Case RegistryHive.PerformanceData
                        objParent = RegistryKey.OpenRemoteBaseKey(RegistryHive.PerformanceData, MachineName)
                    Case RegistryHive.Users
                        objParent = RegistryKey.OpenRemoteBaseKey(RegistryHive.Users, MachineName)
                End Select
    
                Try
                    objSubkey = objParent.OpenSubKey(key)
                    If Not IsNothing(objSubkey) Then
                        sAns = (objSubkey.GetValue(ValueName)).ToString
                    End If
                Catch ex As Exception
                    ErrInfo = ex.Message
                Finally
                    If ErrInfo = "" And sAns = "" Then
                        ErrInfo = _
                           "No value found for requested registry key"
                    End If
                End Try
                Return sAns
            End Function
    So this works if I run it from the Hostmachine, but not if I run it from remote machines.
  • searock
    New Member
    • Mar 2010
    • 9

    #2
    And can you tell me what error(s) do you get while running it from a remote machine?

    Comment

    • stickler
      New Member
      • Jul 2010
      • 1

      #3
      could be due to
      Optional ByVal MachineName As String = "localhost" , _

      is a quick response, I haven't analyzed carefully the code

      Comment

      Working...