Results 1 to 3 of 3

Thread: Registry Change

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Posts
    3

    Post

    Please help...

    how can I read from VB the value:
    HKEY_LOCAL_MACHINE\Software\Microsoft\Office\9.0\Access\Jet\4.0\Engines\systemDb\
    Value:'C:\WINDOWS\SYSTEM\...."

    and how can I change the Value to another string ??

    how can I do it as simple as possible ??

  2. #2
    Lively Member
    Join Date
    May 1999
    Location
    India
    Posts
    97

    Post

    Hi there,
    Here's a simple registry class i wrote to READ in values from the registry. insert it into your project n u're welcome to use it.

    For writing data into the registry u would need to extend the class your self. But if u're willing to wait for a couple of days, i'm gonna be doing that myself soon.

    Cheers.

    Here u go ....


    '=================================================================================================
    ' FileName : clsRegistry
    ' Author : Gaurav Mahindra.
    ' Description : This file contains all the registry constants which are used to read information from registery.
    ' Callable : GetRegistryNameValue
    '=================================================================================================
    Option Explicit

    Private szBaseKey As String ' Holds the Base key that an object should work with.
    Private szBaseHive As REG_HIVES ' Holds the Base key that an object should work with, ex: for the GetSettings
    ' routine in VB the base Hive is HKEY_CURRENT_USER.
    Private szRegKeyRetrieved As String ' Retrieved Values from the Wrapper
    Private lRegKeyRetrieved As Long ' for the string as well as DWORD key types

    Public Enum REG_KEYTYPE
    REG_SZ = 1
    REG_BINARY = 3 ' Free form binary
    REG_DWORD = 4
    End Enum

    Private lpKeyType As Long ' DWORD type key value
    Private szRegHkey As String ' String type Key value retreived from the registry

    Public Enum REG_HIVES
    HKEY_CLASSES_ROOT = &H80000000
    HKEY_CURRENT_USER = &H80000001
    HKEY_LOCAL_MACHINE = &H80000002
    HKEY_USERS = &H80000003
    HKEY_DYN_DATA = &H80000006
    HKEY_CURRENT_CONFIG = &H80000005
    End Enum

    Private Enum REG_ERROR_CODES
    ERROR_SUCCESS = 0&
    ERROR_NONE = 0
    ERROR_BADDB = 1
    ERROR_BADKEY = 2
    ERROR_CANTOPEN = 3
    ERROR_CANTREAD = 4
    ERROR_CANTWRITE = 5
    ERROR_OUTOFMEMORY = 6
    ERROR_INVALID_PARAMETER = 7
    ERROR_ACCESS_DENIED = 8
    ERROR_INVALID_PARAMETERS = 87
    ERROR_NO_MORE_ITEMS = 259
    End Enum


    Private Const RESERVED = 0& ' Windows reserved parameter, used by std SDK registry access routines.
    Private Const READ_CONTROL = &H20000
    Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
    Private Const SYNCHRONIZE = &H100000
    Private Const REG_OPTION_NON_VOLATILE = 0
    Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000

    Private Enum KEY_ACCESS_RIGHTS
    KEY_ENUMERATE_SUB_KEYS = &H8
    KEY_NOTIFY = &H10
    KEY_ALL_ACCESS = &H3F
    KEY_QUERY_VALUE = &H1
    KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
    End Enum

    Private Type SECURITY_ATTRIBUTES ' Define the SECURITY_ATTRIBUTES structure.
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
    End Type

    ' Reg open Key
    Private 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

    ' Reg Query value Ex
    Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Any, lpcbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value.

    Private 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

    Private 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

    Private 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

    Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal Hkey As Long, ByVal lpValueName As String, ByVal RESERVED As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value.
    Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal Hkey As Long, ByVal lpSubKey As String, ByVal RESERVED As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long

    ' Reg Close key
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long

    Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, _
    ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, arguments As Long) As Long
    Private Declare Function GetLastError Lib "kernel32" () As Long

    Private Function GetRegistryNameValue(Hkey As REG_HIVES, szHkeySubKey As String, szSubKeyName As String, lSubKeyType As REG_KEYTYPE) As Boolean
    ' _________________________________________________________________________________________
    ' Sub : GetRegistryNameValue
    ' Author : Gaurav Mahindra
    ' Date : 20th January 2000.
    ' Description : This routine will access the registry and read in the key value based on parameters passed to it.
    ' Uses : Nothing
    ' Input : Hkey - Reg hive to read from.
    ' szHkeySubKey - Reg subkey to read from in the specified hive.
    ' szSubKeyName - Name of the name-value pait in the registry, that has to be read.
    ' lSubKeyType - Key type, String, Dword or binary.
    ' Returns : status - Bool, flags registry read Success/Failure.
    ' _________________________________________________________________________________________
    Dim lSize As Long
    Dim lReturn As Long
    Dim lHandleToHKEY As Long
    Dim lReturnDWORDValue As Long
    Dim szReturnStringValue As String
    Dim status As Boolean ' Flags whether the registry read was successful or not.

    Err.Clear
    szReturnStringValue = String$(255, 0) ' Allocate space for the return value to be read in from the registry.
    lSize = Len(szReturnStringValue) + 1 ' Then open the registry key, from which information is required.

    lReturn = RegOpenKeyEx(Hkey, szHkeySubKey, RESERVED, KEY_QUERY_VALUE, lHandleToHKEY)

    If lSubKeyType = REG_SZ Then
    lReturn = RegQueryValueEx(lHandleToHKEY, szSubKeyName, RESERVED, lSubKeyType, szReturnStringValue, lSize)
    ElseIf lSubKeyType = REG_DWORD Then
    lReturn = RegQueryValueExLong(lHandleToHKEY, szSubKeyName, RESERVED, lSubKeyType, lReturnDWORDValue, lSize)
    End If

    If lReturn <> ERROR_S

  3. #3
    Junior Member
    Join Date
    Jan 1999
    Posts
    26

    Post


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width