Andir Centurion

Joined: 21 Dec 2003 Posts: 184 Location: Chicago Area
|
Posted: Apr 15th, 2004 08:53 AM Post subject: Reading Registry Values (remote registry method) |
|
|
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. |
|