Solved

Accessing Registry values

Posted on 2001-07-18
37
386 Views
Last Modified: 2012-06-22
I am using the following code to update the registry key values

Dim Reg As New Registry
Result = Reg.UpdateKey (HKEY_CURRENT_USER, "Software\ADOBE\Acrobat PDFWriter", "PDFFileName", "123")

The value gets updated fine...
Is there a way in which I can retrueve the key values. I tried using GetKeyValue() but it doesnt works....

0
Comment
Question by:nuts123
  • 13
  • 10
  • 8
  • +5
37 Comments
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
nuts, where did you download the registry class from? I would assume that there is some help/instructions with it. If not then you should be able to look through the class file and find the appropriate function for looking up the values. I cannot help more without knowing which class you are using.
0
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
Hi nuts123,

Get registry code on:

http://www.vbcode.com/asp/code.asp?lstCategory=Registry

'Hope will help.
0
 
LVL 2

Expert Comment

by:nahumd
Comment Utility
Use GetSetting and SaveSetting instead:

SaveSetting "AppName", "section", "key", value

and

x = GetSetting("AppName", "section", "key")
0
 

Author Comment

by:nuts123
Comment Utility
This class can be used by checking the REGISTRY ACCESS FUNCTION in VB-Enterprise Edition... I am not importing it from any other place.
0
 

Author Comment

by:nuts123
Comment Utility
This class can be used by checking the REGISTRY ACCESS FUNCTION in VB-Enterprise Edition... I am not importing it from any other place.
0
 
LVL 8

Expert Comment

by:Dave_Greene
Comment Utility
Here ya go

Dim sValue As String
sValue = ""

KeyFound = Reg.GetKeyValue(HKEY_CURRENT_USER, _
    "Software\ADOBE\Acrobat PDFWriter", "PDFFileName", sValue)
0
 
LVL 5

Expert Comment

by:AndrewDev
Comment Utility
Try this
Add and Retrieve Multiple Values to the Registry
http://www.freevbcode.com/ShowCode.Asp?ID=2475

Regards
Andrew
0
 
LVL 5

Expert Comment

by:AndrewDev
Comment Utility
or this

Registry Manipluation .DLL
http://www.freevbcode.com/ShowCode.Asp?ID=2887

0
 

Author Comment

by:nuts123
Comment Utility
This class can be used by checking the REGISTRY ACCESS FUNCTION in VB-Enterprise Edition... I am not importing it from any other place.
0
 
LVL 4

Expert Comment

by:VincentLawlor
Comment Utility
You need to do the following

Add this to a module or class module
 
Public Declare Function RegQueryValue Lib "advapi32.dll" Alias "RegQueryValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpValue As String, lpcbValue As Long) As Long

Public Function ReadStringValue(ByVal hKeyRoot As REGISTRY_HKEYROOTS, ByVal strKeyPath As String, ByVal strValueName As String, ByVal strDefaultValue As String) As String
Dim bNoErrors As Boolean
Dim lAPIReturnValue As Long
Dim hKey As Long
Dim strValue As String
Dim lValueLength As Long
Dim lValueType As Long
 
On Error GoTo ErrorHandler
 
    bNoErrors = True
    ' first of all, open the key and check for any errors
    lAPIReturnValue = RegOpenKeyEx(hKeyRoot, strKeyPath, 0, KEY_READ, hKey)
    If (lAPIReturnValue <> ERROR_SUCCESS) Then
        ' we couldn't open the key, so let's try to create it
        lAPIReturnValue = RegCreateKeyEx(hKeyRoot, strKeyPath, 0, 0, 0, KEY_ALL_ACCESS, 0, hKey, 0)
        If (lAPIReturnValue <> ERROR_SUCCESS) Then
            ' we could neither open nor create the key, something's wrong
            bNoErrors = False
            strValue = strDefaultValue
        End If
    End If
 
    If bNoErrors Then
        ' now, query the value once to find out the size of the key value
        lAPIReturnValue = RegQueryStringValueEx(hKey, strValueName, 0, lValueType, strValue, lValueLength)
        If (lAPIReturnValue = ERROR_SUCCESS) Then
            ' if the value is queried successfully then fill out the strValue variable
            ' with spaces so that it is large enough to accept the value
            If (lValueLength > 0) Then
                strValue = Space(lValueLength - 1)
            Else
                strValue = "" 'Space(1)
            End If
            ' now query the value again - this time strValue is large enough to
            ' hold the information we're looking for.
            lAPIReturnValue = RegQueryStringValueEx(hKey, strValueName, 0, lValueType, strValue, lValueLength)
            If (lAPIReturnValue <> ERROR_SUCCESS) Or (lValueType <> REG_SZ) Then
                bNoErrors = False
                strValue = strDefaultValue
            End If
        Else
            ' the value could not be read, so let's write the default value to the registry instead
           
            ' The key value may not exist in the registry so try to create it
            lAPIReturnValue = RegCreateKeyEx(hKeyRoot, strKeyPath, 0, 0, 0, KEY_ALL_ACCESS, 0, hKey, 0)
           
            ' Try to set the value now
            lAPIReturnValue = RegSetStringValueEx(hKey, strValueName, 0, REG_SZ, strDefaultValue, Len(strDefaultValue) + 1)
           
            strValue = strDefaultValue ' we'll be using the default value now anyway
            If lAPIReturnValue <> ERROR_SUCCESS Then
                ' if we couldn't write the value, let's flag the error
                bNoErrors = False
            End If
        End If
    End If
 
    ' close the key (avoids corruption of the registry)
    lAPIReturnValue = RegCloseKey(hKeyRoot)
    ' finally return the value we got
    ReadStringValue = strValue
 
Exit Function
ErrorHandler:
    ' an unexpected error has occurred
    Dim strMessage
   
   
    MsgBox "An error occurred reading a string value from the registry " & vbCrLf & vbCrLf _
            & Err.Number & " : " & Err.Description

   
    Resume Next
End Function

Public Sub WriteStringValue(ByVal hKeyRoot As REGISTRY_HKEYROOTS, ByVal strKeyPath As String, ByVal strValueName As String, strValue As String)
Dim bNoErrors As Boolean
Dim lAPIReturnValue As Long
Dim hKey As Long
Dim lValueLength As Long
Dim lValueType As Long
 
On Error GoTo ErrorHandler
 
    bNoErrors = True
    ' first of all, open the key and check for any errors
    lAPIReturnValue = RegOpenKeyEx(hKeyRoot, strKeyPath, 0, KEY_ALL_ACCESS, hKey)
    If (lAPIReturnValue <> ERROR_SUCCESS) Then
        ' we couldn't open the key, so let's try to create it
        lAPIReturnValue = RegCreateKeyEx(hKeyRoot, strKeyPath, 0, 0, 0, KEY_ALL_ACCESS, 0, hKey, 0)
        If (lAPIReturnValue <> ERROR_SUCCESS) Then
            ' we could neither open nor create the key, something's wrong
            bNoErrors = False
        End If
    End If
 
    If bNoErrors Then
        ' now we've opened the key, so let's write the value
        lAPIReturnValue = RegSetStringValueEx(hKey, strValueName, 0, REG_SZ, strValue, Len(strValue)) '+1)
        If lAPIReturnValue <> ERROR_SUCCESS Then
            ' if we couldn't write the value, let's flag the error
            bNoErrors = False
        End If
    End If
 
    ' close the key (avoids corruption of the registry)
    RegCloseKey (hKeyRoot)
 
Exit Sub
ErrorHandler:
    ' an unexpected error has occurred
    bNoErrors = False
   
    Dim strMessage
   
    MsgBox "An error occurred writing a string value to the registry " & vbCrLf & vbCrLf _
            & Err.Number & " : " & Err.Description
   
    Resume Next
End Sub


Public Function ReadDWORDValue(ByVal hKeyRoot As REGISTRY_HKEYROOTS, ByVal strKeyPath As String, ByVal strValueName As String, ByVal dwDefaultValue As Long) As Long
Dim bNoErrors As Boolean
Dim lAPIReturnValue As Long
Dim hKey As Long
Dim dwValue As Long
Dim lValueLength As Long
Dim lValueType As Long
 
On Error GoTo ErrorHandler
 
    bNoErrors = True
    ' first of all, open the key and check for any errors
    lAPIReturnValue = RegOpenKeyEx(hKeyRoot, strKeyPath, 0, KEY_READ, hKey)
    If (lAPIReturnValue <> ERROR_SUCCESS) Then
        ' we couldn't open the key, so let's try to create it
        lAPIReturnValue = RegCreateKeyEx(hKeyRoot, strKeyPath, 0, 0, 0, KEY_ALL_ACCESS, 0, hKey, 0)
        If (lAPIReturnValue <> ERROR_SUCCESS) Then
            ' we could neither open nor create the key, something's wrong
            bNoErrors = False
            dwValue = dwDefaultValue
        End If
    End If
 
    If bNoErrors Then
        ' now, query the value once to find out the size of the key value
        lAPIReturnValue = RegQueryValueEx(hKey, strValueName, 0, lValueType, dwValue, lValueLength)
        If (lAPIReturnValue = ERROR_MORE_DATA) Then
            ' for some reason which I don't understand, the first call to RegQueryEx always
            ' returns ERROR_MORE_DATA even though the dwValue is always big enough to hold
            ' the DWORD data - calling it a second time always seems to work - FS
            lAPIReturnValue = RegQueryValueEx(hKey, strValueName, 0, lValueType, dwValue, lValueLength)
        End If
 
        If (lAPIReturnValue <> ERROR_SUCCESS) Then
            ' the value could not be read, so let's write the default value to the registry instead
           
            ' The registry key value may not exist try to create it
            lAPIReturnValue = RegCreateKeyEx(hKeyRoot, strKeyPath, 0, 0, 0, KEY_ALL_ACCESS, 0, hKey, 0)
           
            ' Try to set the value
            lAPIReturnValue = RegSetValueEx(hKey, strValueName, 0, REG_DWORD, (dwDefaultValue), Len(dwDefaultValue))
           
            dwValue = dwDefaultValue ' we'll be using the default value now anyway
            If lAPIReturnValue <> ERROR_SUCCESS Then
                ' if we couldn't write the value, let's flag the error
                bNoErrors = False
            End If
        End If
    End If
 
    ' close the key (avoids corruption of the registry)
    RegCloseKey (hKeyRoot)
    ' finally return the value we got
    ReadDWORDValue = dwValue
 
Exit Function
ErrorHandler:
    ' an unexpected error has occurred
    bNoErrors = False
    dwValue = dwDefaultValue
   
    Dim strMessage
   
    MsgBox "An error occurred reading a DWORD value from the registry " & vbCrLf & vbCrLf _
            & Err.Number & " : " & Err.Description
   
    Resume Next
End Function

This will read DWORD and String values from the registry for you.

e.g. to use it

ReadStringValue(HKEY_LOCAL_MACHINE, "Software\ADOBE\Acrobat PDFWriter", "PDFFileName", "123")

Hope this helps

Vin.
0
 
LVL 4

Expert Comment

by:VincentLawlor
Comment Utility
Don't for get to assign the return value to a string.

Vin.
0
 
LVL 1

Expert Comment

by:SimonE
Comment Utility
nuts, to get around the annoying inability of VB to read back from anywhere other than the VB and VBA program settings, try using this code as a module in your application.  Call the readregistry method with the parameters you want.  I have found it works really well.


'' Created by E.Spencer (elliot@spnc.demon.co.uk) - This code is public domain.'
Option Explicit
'Security Mask constants
Public Const READ_CONTROL = &H20000
Public Const SYNCHRONIZE = &H100000
Public Const STANDARD_RIGHTS_ALL = &H1F0000
Public Const STANDARD_RIGHTS_READ = READ_CONTROL
Public Const STANDARD_RIGHTS_WRITE = READ_CONTROL
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_SET_VALUE = &H2
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const KEY_NOTIFY = &H10
Public Const KEY_CREATE_LINK = &H20
Public 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 Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or _
   KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Public Const KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))
Public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE _
   Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE)) ' Possible registry data types
Public Enum InTypes
    ValNull = 0
    ValString = 1
    ValXString = 2
    ValBinary = 3
    ValDWord = 4
    ValLink = 6
    ValMultiString = 7
    ValResList = 8
End Enum
' Registry value type definitions
Public Const REG_NONE As Long = 0
Public Const REG_SZ As Long = 1
Public Const REG_EXPAND_SZ As Long = 2
Public Const REG_BINARY As Long = 3
Public Const REG_DWORD As Long = 4
Public Const REG_LINK As Long = 6
Public Const REG_MULTI_SZ As Long = 7
Public Const REG_RESOURCE_LIST As Long = 8
' Registry section definitionsPublic Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_DYN_DATA = &H80000006 ' Codes returned by Reg API calls
Private Const ERROR_NONE = 0
Private Const ERROR_BADDB = 1
Private Const ERROR_BADKEY = 2
Private Const ERROR_CANTOPEN = 3
Private Const ERROR_CANTREAD = 4
Private Const ERROR_CANTWRITE = 5
Private Const ERROR_OUTOFMEMORY = 6
Private Const ERROR_INVALID_PARAMETER = 7
Private Const ERROR_ACCESS_DENIED = 8
Private Const ERROR_INVALID_PARAMETERS = 87
Private Const ERROR_NO_MORE_ITEMS = 259
' Registry API functions used in this module (there are more of them)
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult 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 String, lpcbData As Long) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private 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
Private 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
Private Declare Function RegFlushKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
' This routine allows you to get values from anywhere in the Registry, it currently
' only handles string, double word and binary values. Binary values are returned as
' hex strings.'' Example
' Text1.Text = ReadRegistry(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName")
'
Public Function ReadRegistry(ByVal Group As Long, ByVal Section As String, ByVal Key As String) As String
Dim lResult As Long, lKeyValue As Long, lDataTypeValue As Long, lValueLength As Long, sValue As String, td As Double
Dim TStr1 As String
Dim TStr2 As String
Dim i As Integer

On Error Resume Next
lResult = RegOpenKey(Group, Section, lKeyValue)
sValue = Space$(2048)
lValueLength = Len(sValue)
lResult = RegQueryValueEx(lKeyValue, Key, 0&, lDataTypeValue, sValue, lValueLength)
If (lResult = 0) And (Err.Number = 0) Then
    If lDataTypeValue = REG_DWORD Then
      td = Asc(Mid$(sValue, 1, 1)) + &H100& * Asc(Mid$(sValue, 2, 1)) + &H10000 * Asc(Mid$(sValue, 3, 1)) + &H1000000 * CDbl(Asc(Mid$(sValue, 4, 1)))
      sValue = Format$(td, "000")
    End If
    If lDataTypeValue = REG_BINARY Then
       ' Return a binary field as a hex string (2 chars per byte)
       TStr2 = ""
       For i = 1 To lValueLength
          TStr1 = Hex(Asc(Mid(sValue, i, 1)))
          If Len(TStr1) = 1 Then TStr1 = "0" & TStr1
          TStr2 = TStr2 + TStr1
        Next
        sValue = TStr2
    Else
      sValue = Left$(sValue, lValueLength - 1)
    End If
Else
   sValue = "Not Found"
End If
lResult = RegCloseKey(lKeyValue)
ReadRegistry = sValue

End Function

0
 
LVL 8

Expert Comment

by:Dave_Greene
Comment Utility
Nuts,

Here is the answer to your question, just in case you missed it  :)


Dim sValue As String
dim KeyFound  as Long
 
sValue = ""

KeyFound = Reg.GetKeyValue(HKEY_CURRENT_USER, _
   "Software\ADOBE\Acrobat PDFWriter", "PDFFileName", sValue)
0
 
LVL 8

Accepted Solution

by:
Dave_Greene earned 100 total points
Comment Utility
Mistake, actually KeyFound is a Boolean value...

Dim KeyFound  as Boolean

0
 
LVL 4

Expert Comment

by:VincentLawlor
Comment Utility
public enums - used in calls to the Read*Value functions
Public Enum REGISTRY_HKEYROOTS
    HKEY_CLASSES_ROOT = &H80000000
    HKEY_CURRENT_CONFIG = &H80000005
    HKEY_CURRENT_USER = &H80000001
    HKEY_DYN_DATA = &H80000006
    HKEY_LOCAL_MACHINE = &H80000002
    HKEY_PERFORMANCE_DATA = &H80000004
    HKEY_USERS = &H80000003
End Enum


' used in RegEnumKeyEx
Private Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type

'Registry API Declarations

' Types used by the registry API functions
Private Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Long
End Type


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 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, ByVal lpSecurityAttributes As Long, phkResult As Long, lpdwDisposition 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, 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 RegQueryStringValueEx 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         ' Note that if you declare the lpData parameter as String, you must pass it By Value.

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 RegSetStringValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, 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 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


'Registry Security Constants
Private Const STANDARD_RIGHTS_ALL As Long = &H1F0000
Private Const SYNCHRONIZE As Long = &H100000
Private Const READ_CONTROL As Long = &H20000
Private Const STANDARD_RIGHTS_READ As Long = (READ_CONTROL)
Private Const STANDARD_RIGHTS_WRITE As Long = (READ_CONTROL)

Private Const KEY_QUERY_VALUE As Long = &H1
Private Const KEY_SET_VALUE As Long = &H2
Private Const KEY_CREATE_SUB_KEY As Long = &H4
Private Const KEY_ENUMERATE_SUB_KEYS As Long = &H8
Private Const KEY_NOTIFY As Long = &H10
Private Const KEY_CREATE_LINK As Long = &H20
Private Const KEY_READ As Long = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Private Const KEY_WRITE As Long = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
Private Const KEY_ALL_ACCESS As Long = ((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))

' Registry Data Type Constants
Private Const REG_SZ As Long = 1        ' null-terminated string
Private Const REG_DWORD As Long = 4     ' 32-bit number (i.e. a long)

Private Const REG_OPTION_NON_VOLATILE As Long = 0

' Error values
Private Const ERROR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&
Private Const ERROR_NO_MORE_ITEMS As Long = 259&

Paste these in also

Vin.
0
 

Author Comment

by:nuts123
Comment Utility
This class can be used by checking the REGISTRY ACCESS FUNCTION in VB-Enterprise Edition... I am not importing it from any other place.
0
 
LVL 4

Expert Comment

by:VincentLawlor
Comment Utility
Sorry missed that bit.

Vin.
0
 
LVL 4

Expert Comment

by:VincentLawlor
Comment Utility
Dim Reg As New Registry
    Dim result
    Dim strResult As String
    result = Reg.UpdateKey(HKEY_CURRENT_USER, "Software\ADOBE\Acrobat PDFWriter", "PDFFileName", "123")
    result = Reg.GetKeyValue(HKEY_CURRENT_USER, "Software\ADOBE\Acrobat PDFWriter", "PDFFileName", strResult)

Tried this code and it works just fine.

Vin.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 8

Expert Comment

by:Dave_Greene
Comment Utility
I already placed that code Vincent... twice now
0
 

Author Comment

by:nuts123
Comment Utility
This class can be used by checking the REGISTRY ACCESS FUNCTION in VB-Enterprise Edition... I am not importing it from any other place.
0
 
LVL 4

Expert Comment

by:VincentLawlor
Comment Utility
David
I was just making a comment not offering a solution i.e. that the code you posted works.


David__Greene's code looks like the answer.

Is that better seesh.

Vin.



0
 
LVL 8

Expert Comment

by:Dave_Greene
Comment Utility
Usually if you agree with someones comment on EE you simple state something to the affect of "I agree with Dave_Greene, tried his code and it works!"  Else it looks like you are trying to take credit for someone elses suggestion.
0
 

Author Comment

by:nuts123
Comment Utility
This class can be used by checking the REGISTRY ACCESS FUNCTION in VB-Enterprise Edition... I am not importing it from any other place.
0
 
LVL 4

Expert Comment

by:VincentLawlor
Comment Utility
Sorry Dave.

I'm sure he noticed your suggestion.

Vin.
0
 

Author Comment

by:nuts123
Comment Utility
Hey Guys! dont fight over this...
Thanks a lot to all of u.. Dave code worked.. I was trying it out actually but hadnt declared the 'SValue' varaible
Thanks anyways.
0
 

Author Comment

by:nuts123
Comment Utility
Hey Guys! dont fight over this...
Thanks a lot to all of u.. Dave code worked.. I was trying it out actually but hadnt declared the 'SValue' varaible
Thanks anyways.
0
 

Author Comment

by:nuts123
Comment Utility
Hey Guys! dont fight over this...
Thanks a lot to all of u.. Dave code worked.. I was trying it out actually but hadnt declared the 'SValue' varaible
Thanks anyways.
0
 

Author Comment

by:nuts123
Comment Utility
Hey Guys! dont fight over this...
Thanks a lot to all of u.. Dave code worked.. I was trying it out actually but hadnt declared the 'SValue' varaible
Thanks anyways.
0
 

Author Comment

by:nuts123
Comment Utility
Hey Guys! dont fight over this...
Thanks a lot to all of u.. Dave code worked.. I was trying it out actually but hadnt declared the 'SValue' varaible
Thanks anyways.
0
 
LVL 8

Expert Comment

by:Dave_Greene
Comment Utility
All this for a "B", I guess I needed to go to his cube and insert the line myself for an "A"...  You people, I swear...
0
 
LVL 4

Expert Comment

by:VincentLawlor
Comment Utility
Well he did practically give you the answer in the question.

Vin.
0
 
LVL 8

Expert Comment

by:Dave_Greene
Comment Utility
Vincent, if he had the answer he wouldn't have posed the question.  And if it was so apparent then why did you post the 300 lines of old registry code?

Check-Mate
0
 
LVL 4

Expert Comment

by:VincentLawlor
Comment Utility
I am only messing with you do you have no sense of humour.

I posted 300 lines of olde registry code because they work. And hadn't realised he was using that registry function.

Vin.
0
 
LVL 8

Expert Comment

by:Dave_Greene
Comment Utility
:) Peace then  :)

Cheers!
0
 
LVL 4

Expert Comment

by:VincentLawlor
Comment Utility
K So.

:-)

Vin.
0
 

Author Comment

by:nuts123
Comment Utility
Hey Guys! dont fight over this...
Thanks a lot to all of u.. Dave code worked.. I was trying it out actually but hadnt declared the 'SValue' varaible
Thanks anyways.
0
 

Author Comment

by:nuts123
Comment Utility
Hey Guys! dont fight over this...
Thanks a lot to all of u.. Dave code worked.. I was trying it out actually but hadnt declared the 'SValue' varaible
Thanks anyways.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now