2 Replies - 757 Views - Last Post: 09 April 2013 - 10:18 AM Rate Topic: -----

#1 Graywalker  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 22-February 13

Odd problem with OpenRemoteBaseKey

Posted 09 April 2013 - 06:14 AM

I ran across this issue working on getting some information about several computers in our business network.

I'm trying to get the OS Architecture (among other items) using code like :

Function GetArch(Name As String)
        Dim bitsize As Integer
        Dim rvalue As String = "unbelieveable"
        'MsgBox(Name)
        Dim MainKey As String = "LM"
        Dim subKey As String = "SOFTWARE\Microsoft\Windows\CurrentVersion"
        Dim Value As String = "ProgramFilesPath"
        rvalue = U.RegRead(Name, MainKey, subKey, Value)
        
        If InStr(rvalue, "not") Or InStr(rvalue, "unauthorized") Then
            bitsize = "Registry Error"
        Else
            Dim index As Integer = InStr(rvalue, "(x86)")
            'MsgBox(Name & vbCrLf & rvalue & vbCrLf & index)
            If index > 2 Then
                bitsize = 64
            Else
                bitsize = 32
            End If

        End If

        Return bitsize
    End Function


in my "U" class - for "Utilities" - is the regread, which takes arguments and reads the right key.

 Select Case Mainkey
            Case Is = "LM"
                Try
                    MsgBox(CompName)
                    RemRegKey = RegistryKey.OpenRemoteBaseKey( _
                        RegistryHive.LocalMachine, CompName).OpenSubKey(RegKey)
                    MsgBox("Local Machine - no error, but " & vbCrLf & RemRegKey.Name.ToString & vbCrLf & RegVal)
                Catch ex As Exception
                    etype = ex.GetType().Name
                    myerror = ex.Message.ToString
                    MsgBox("Error : " & etype & vbCrLf & myerror)
                End Try



The first item requested doesn't get caught on the RemRegKey line, it does get caught with the MsgBox as a Null Reference error. Comment out the MsgBox line in the Try and no problem - except that the local registry is read and a wrong value returned for the remote computer.
The second item works properly, so does the third, fourth, fifth, etc.

The big problem is that I am getting wrong information on the OS Architecture. I am assuming because it is reading the local registry instead of the remote registry. I am testing the remote read on a 32 bit machine, my local machine is 64 bit. Other information from the remote localmachine registry is correct and not the same as my local machine. Code is no different, so I am at a loss as to WHY.

Any ideas on how to make sure that I am getting the right information every time?

Is This A Good Question/Topic? 0
  • +

Replies To: Odd problem with OpenRemoteBaseKey

#2 Graywalker  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 22-February 13

Re: Odd problem with OpenRemoteBaseKey

Posted 09 April 2013 - 08:08 AM

at the very least, how do I tell if it read the local registry instead of the remote one? The Catch isn't doing it, because its not throwing an exception.
Was This Post Helpful? 0
  • +
  • -

#3 Graywalker  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 22-February 13

Re: Odd problem with OpenRemoteBaseKey

Posted 09 April 2013 - 10:18 AM

I've figured out that it is some wacked out issue with running it on a 64bit machine requesting info from a 32 bit machine. I've run into it before and it is very stupid.

It is something with having to use :

Dim subKey As String = "SOFTWARE\Microsoft\Windows\Wow6432Node\CurrentVersion"


because 64 bit machines will always try to read 32 bit info in that directory or some such crap as that.

In other code the work-around worked because it wouldn't default and read the local registry.

So I could do :
$OSArch = RegRead("\\" & $ComputerName & "\HKEY_LOCAL_MACHINE\SOFTWARE\CurrentVersion", "ProgramFilesPath")
 If @error Then
    $OSArch = RegRead("\\" & $ComputerName & "\HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\CurrentVersion", "ProgramFilesPath")
    If @error Then
     $OSArch = "Tuner Registry Error!"
    EndIf
 EndIf

VB.NET will error out on the remote computer and return the local registry info without, apparently, any way to tell what happened.

I've switched to using a WMI query to get the OS Architecture, but now I have to question everything VB.Net reads from the registry...

Any suggestions on how to correct this behavior would be greatly appreciated.

This post has been edited by Graywalker: 09 April 2013 - 10:29 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1