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?