Retreiving a value from registry...please help 
Author Message
 Retreiving a value from registry...please help

Hi,
I want to get "retrieve" the following value fron registry

HKEY_LOCAL_MACHINE / SOFTWARE / WINDOWS / CURRENTVERSION / REGISTEREDOWNER

and use it in an application (store it in a variable, or something else). Is
there any way to do it?

Thanks in advance

Fil



Mon, 02 May 2005 02:36:01 GMT  
 Retreiving a value from registry...please help
I guess you meant the key:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RegisteredOwner

============================================================
Option Explicit

' Registry API prototypes
Private Declare Function RegCloseKey Lib "advapi32.dll" ( _
        ByVal hKey As Long) As Long
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
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

' Reg Data Types...
Private Const REG_SZ = 1  ' Unicode nul terminated string

' Reg Key Handles
Private Const HKEY_LOCAL_MACHINE = &H80000002

' Reg Severity Codes
Private Const ERROR_SUCCESS = 0  ' The operation completed successfully

' Reg Key Security Options
Private Const SYNCHRONIZE As Long = &H100000
Private Const STANDARD_RIGHTS_ALL As Long = &H1F0000
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const KEY_CREATE_LINK = &H20
Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or
KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY
Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))

Private Sub Form_Load()
Dim hKey As Long
Dim lData As Long
Dim lRetVal As Long
Dim lValueType As Long
Dim sValue As String

    'open the key
    lRetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
            "Software\Microsoft\Windows\CurrentVersion", _
            0&, KEY_ALL_ACCESS, hKey)
    If lRetVal = ERROR_SUCCESS Then
        ' Determine the size and type of data to be read
        lRetVal = RegQueryValueEx(hKey, _
                "RegisteredOwner", _
                0&, lValueType, ByVal 0&, lData)
    End If
    If lRetVal = ERROR_SUCCESS Then
        If lValueType = REG_SZ Then
            'Create a buffer for the data
            sValue = String$(lData, vbNullChar)
            'Retreve the key's content
            lRetVal = RegQueryValueEx(hKey, "RegisteredOwner", 0&,
lValueType, ByVal sValue, lData)
            If lRetVal = ERROR_SUCCESS Then
                'Remove the unnecessary vbNullChar's
                Me.Caption = Left$(sValue, InStr(1, sValue, vbNullChar) - 1)
            End If
        End If
    End If
    'close the key
    RegCloseKey hKey
End Sub
==============================================================

Johan.


Quote:
> Hi,
> I want to get "retrieve" the following value fron registry

> HKEY_LOCAL_MACHINE / SOFTWARE / WINDOWS / CURRENTVERSION / REGISTEREDOWNER

> and use it in an application (store it in a variable, or something else).
Is
> there any way to do it?

> Thanks in advance

> Fil



Mon, 02 May 2005 06:02:41 GMT  
 Retreiving a value from registry...please help
Try this...

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''
'
' API Declarations
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''
Private Declare Function RegCloseKey Lib "advapi32.dll" _
   (ByVal hKey As Long) As Long

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 Any, _
   hKeyHandle As Long, lpdwDisposition As Long) As Long

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 RegOpenKeyEx Lib "advapi32.dll" _
   Alias "RegOpenKeyExA" _
   (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
   ByVal samDesired As Long, hKeyHandle 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

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''
'
' Constant Declarations
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''
Private Const ERROR_SUCCESS = 0&

Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_CONFIG = &H80000005
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_DYN_DATA = &H80000006
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_PERFORMANCE_DATA = &H80000004
Private Const HKEY_USERS = &H80000003

Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_NOTIFY = &H10
Private Const KEY_CREATE_LINK = &H20
Private Const REG_OPTION_NON_VOLATILE = 0
Private Const REG_SZ = 1
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const SYNCHRONIZE = &H100000

Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or _
   KEY_QUERY_VALUE Or _
   KEY_SET_VALUE Or _
   KEY_CREATE_SUB_KEY Or _
   KEY_ENUMERATE_SUB_KEYS Or _
   KEY_NOTIFY Or _
   KEY_CREATE_LINK) And (Not SYNCHRONIZE))

*************

Public Function fnGetRegistryKey(sKey As String, sEntry As String, lKeyType
As Long, Optional bDirectory As Boolean = False) As String

   Const BUFFER_LENGTH = 255

   Dim sKeyName As String
   Dim sReturnBuffer As String
   Dim lBufLen As Long
   Dim lReturn As Long
   Dim hKeyHandle As Long

   ' Set up return buffer

   sReturnBuffer = Space(BUFFER_LENGTH)
   lBufLen = BUFFER_LENGTH

   lReturn = RegOpenKeyEx(lKeyType, sKey, _
      0, KEY_ALL_ACCESS, hKeyHandle)
   If lReturn = ERROR_SUCCESS Then
      lReturn = RegQueryValueExString(hKeyHandle, sEntry, _
         0, 0, sReturnBuffer, lBufLen)
      If lReturn = ERROR_SUCCESS Then

         ' Have to remove the null terminator at end of string

         sReturnBuffer = Trim$(Left$(sReturnBuffer, lBufLen - 1))

         ' Add a backslash if one isn't already on a
         ' directory entry.

         If bDirectory Then
            If Right$(sReturnBuffer, 1) <> "\" Then
               sReturnBuffer = sReturnBuffer & "\"
            End If
         End If
         fnGetRegistryKey = sReturnBuffer

      Else
         fnGetRegistryKey = ""
      End If
   Else
      fnGetRegistryKey = ""
   End If

   ' Close the key

   RegCloseKey hKeyHandle

End Function

*****************

good luck....

Calan

Quote:

> Hi,
> I want to get "retrieve" the following value fron registry

> HKEY_LOCAL_MACHINE / SOFTWARE / WINDOWS / CURRENTVERSION / REGISTEREDOWNER

> and use it in an application (store it in a variable, or something else).
Is
> there any way to do it?

> Thanks in advance

> Fil



Mon, 02 May 2005 09:26:21 GMT  
 Retreiving a value from registry...please help
BTW...I'm not big into adding controls to my projects, but I just found this
registry ocx that is excellent....easy to use, small, and well documented...

http://www.a1vbcode.com/app.asp?ID=977

Calan

Quote:

> Hi,
> I want to get "retrieve" the following value fron registry

> HKEY_LOCAL_MACHINE / SOFTWARE / WINDOWS / CURRENTVERSION / REGISTEREDOWNER

> and use it in an application (store it in a variable, or something else).
Is
> there any way to do it?

> Thanks in advance

> Fil



Mon, 02 May 2005 11:44:40 GMT  
 Retreiving a value from registry...please help
That's my control!! yay. Someone found it. I didn't even have to point it
out my self :-D.
Cheers, Calan.

Alex


Quote:
> BTW...I'm not big into adding controls to my projects, but I just found
this
> registry ocx that is excellent....easy to use, small, and well
documented...

> http://www.a1vbcode.com/app.asp?ID=977

> Calan


> > Hi,
> > I want to get "retrieve" the following value fron registry

> > HKEY_LOCAL_MACHINE / SOFTWARE / WINDOWS / CURRENTVERSION /
REGISTEREDOWNER

> > and use it in an application (store it in a variable, or something
else).
> Is
> > there any way to do it?

> > Thanks in advance

> > Fil



Tue, 03 May 2005 01:12:27 GMT  
 Retreiving a value from registry...please help
thanks both of you for your assistance.

Very helpfull examples and the link also.

Fil


Quote:
> BTW...I'm not big into adding controls to my projects, but I just found
this
> registry ocx that is excellent....easy to use, small, and well
documented...

> http://www.a1vbcode.com/app.asp?ID=977

> Calan


> > Hi,
> > I want to get "retrieve" the following value fron registry

> > HKEY_LOCAL_MACHINE / SOFTWARE / WINDOWS / CURRENTVERSION /
REGISTEREDOWNER

> > and use it in an application (store it in a variable, or something
else).
> Is
> > there any way to do it?

> > Thanks in advance

> > Fil



Tue, 03 May 2005 05:49:51 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Reading Registry value, help me please,please

2. Retreiving value for key from Registry

3. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

4. Registry Problems Help Please! - registry.bas (0/1)

5. Registry Problems Help Please! - registry.bas (1/1)

6. please help retreiving specific data...

7. Registry keys and values - second try, can MS please answer

8. Retreiving Registry Setting in Access97

9. Storing and retreiving numbers in Registry careless of Regional Settings

10. retreiving info from Registry

11. Can anyone HELP me PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE

12. Retreive values from a Module

 

 
Powered by phpBB® Forum Software