Class Registry

Get/Set Windows registry values
'ClassRegistry:

Option Public
Option Explicit




'// API Constants
Const REG_SZ = 1
Const REG_DWORD = 4

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003

Const ERROR_NONE = 0
Const ERROR_BADDB = 1
Const ERROR_BADKEY = 2
Const ERROR_CANTOPEN = 3
Const ERROR_CANTREAD = 4
Const ERROR_CANTWRITE = 5
Const ERROR_OUTOFMEMORY = 6
Const ERROR_INVALID_PARAMETER = 7
Const ERROR_ACCESS_DENIED = 8
Const ERROR_INVALID_PARAMETERS = 87
Const ERROR_NO_MORE_ITEMS = 259

Const KEY_ALL_ACCESS = &H3F
Const REG_OPTION_NON_VOLATILE = 0
Const REG_PARAMETER_IS_RESERVED = 0
Const REG_DEFAULT_VALUE = ""

Const cMAXLEN_BUFFER = 255

'// API Declarations
Declare Function RegCloseKey Lib "advapi32.dll" (Byval hKey As Long) As Long
Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (Byval
hKey As Long, Byval lpSubKey As String, Byval ulOptions As Long, Byval
samDesired As Long, phkResult As Long) As Long
Declare Function RegQueryValueExString Lib "advapi32.dll" Alias
"RegQueryValueExA" (Byval hKey As Long, Byval lpValueName As String, Byval
lpReserved As Long, lpType As Long, Byval lpData As String, lpcbData As Long)
As Long
Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias
"RegQueryValueExA" (Byval hKey As Long, Byval lpValueName As String, Byval
lpReserved As Long, lpType As Long, lpData As Long, lpcbData As Long) As Long
Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias
"RegQueryValueExA" (Byval hKey As Long, Byval lpValueName As String, Byval
lpReserved As Long, lpType As Long, Byval lpData As Long, lpcbData As Long) As
Long
Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA"
(Byval hKey As Long, Byval lpValueName As String, Byval Reserved As Long, Byval
dwType As Long, Byval lpValue As String, Byval cbData As Long) As Long
Declare Function RegSetValueExLong Lib "advapi32.dll" Alias "RegSetValueExA"
(Byval hKey As Long, Byval lpValueName As String, Byval Reserved As Long, Byval
dwType As Long, lpValue As Long, Byval cbData As Long) As Long


Const cREG_COMPONENTS_PATH = "Software\Lotus\Lotus Components\1.0"
Const cREG_COMPONENTS_KEYNAME = "LoaderPath"

Class Registry

'// Declare Member Varaibles
Private hkey As Long

'// Declare Member Code
Declare Public Function GetValue( ItemName$ ) As String
Declare Public Function SetValue( ValueName As String, lType As Long, vValue As
Variant) As Long

'// Constructor
Sub New( Section, KeyName$ )
Call RegOpenKeyEx(Section, KeyName$, REG_PARAMETER_IS_RESERVED,
KEY_ALL_ACCESS, Me.hKey)
End Sub

'// Destructor
Sub Delete()
Call RegCloseKey (Me.hKey)
End Sub

Public Function GetValue( ItemName$ ) As String
Dim sData As String
Dim lpcbData As Long
Dim lpType As Long

'// First we initialize the buffer
sData = String(cMAXLEN_BUFFER, 0)
lpcbData = Len(sData)

'// Get it
Call RegQueryValueExString( Me.hKey, ItemName$,
REG_PARAMETER_IS_RESERVED, lpType, sData, lpcbData)

'// Return
GetValue = Left( sData, Instr( 1, sData, Chr$(0) )-1)


End Function

Public Function SetValue( ValueName As String, lType As Long, vValue As
Variant) As Long
Dim lValue As Long
Dim sValue As String

Select Case lType
Case REG_SZ

'//sValue gets assigned the value vValue
sValue = vValue

'// Set value to Windows

This was first published in November 2000
This Content Component encountered an error

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close