Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » .NET Knowledge Base

Post new topic   Reply to topic
Reading Registry Values (remote registry method)
View previous topic :: View next topic  
Author Message
Andir
Centurion


Joined: 21 Dec 2003
Posts: 184
Location: Chicago Area

PostPosted: Apr 15th, 2004 08:53 AM    Post subject: Reading Registry Values (remote registry method) Reply with quote

The following functions allow you to connect to the Remote Registry Service on any network PC and return a value that you specify.

To write out the response to the console window you would call this with a line similar to:
Console.WriteLine(fnGetRegValue("<any pc name>", "HKLM", "software\microsoft\windows\currentversion", "ProductId"))

Code:

' This will go on one of the very first lines at the top above the Class

Imports Microsoft.Win32

'  Your Class definitions/form modules etc will start here.

        Private Function fnGetRegValue(ByVal machineName As String, ByVal rootKey As String, ByVal pathKey As String, ByVal variable As String) As String
                Dim reg As RegistryKey
                Dim regHive As RegistryHive
                Dim regKey As RegistryKey
                regHive = fnConvertRegHive(rootKey)
                Try
                        reg = RegistryKey.OpenRemoteBaseKey(regHive, machineName)
                Catch ex As Exception
                        fnGetRegValue = "Unable to open Registry: " & ex.Message
                        Exit Function
                End Try
                regKey = reg.OpenSubKey(pathKey)
                fnGetRegValue = regKey.GetValue(variable)
                regKey.Close()
        End Function

        Private Function fnConvertRegHive(ByVal hiveName As String) As RegistryHive
                Select Case UCase(hiveName)
                        Case "HKCU", "HKEY_CURRENT_USER"
                                fnConvertRegHive = RegistryHive.CurrentUser
                        Case "HKCR", "HKEY_CLASSES_ROOT"
                                fnConvertRegHive = RegistryHive.ClassesRoot
                        Case "HKLM", "HKEY_LOCAL_MACHINE"
                                fnConvertRegHive = RegistryHive.LocalMachine
                        Case "HKU", "HKEY_USERS"
                                fnConvertRegHive = RegistryHive.Users
                        Case "HKCC", "HKEY_CURRENT_CONFIG"
                                fnConvertRegHive = RegistryHive.CurrentConfig
                        Case "HKPD", "HKEY_PERFORMANCE_DATA"
                                fnConvertRegHive = RegistryHive.PerformanceData
                        Case "HKDD", "HKEY_DYN_DATA"
                                fnConvertRegHive = RegistryHive.DynData
                End Select
        End Function

'  Your Class definitions/form modules etc will end here.  Usually End Class

_________________
If you happen to see little people sitting on your desk...don't tell anyone or they might think your crazy too.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » .NET Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic