Results 1 to 12 of 12

Thread: Change RegEdit temporary when I start a form?

  1. #1
    Pirre001
    Guest

    Question

    I wanna change a setting temporary in RegEdit when i start a form. Then when I close the form the Settings will go back to default value.

    The changes I Wanna do when I start the form is this:

    \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.5\Engines\Text\

    Change this value to:

    Format "TabDelimited"


    I would be very greateful if anybody could help me.

  2. #2
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    I think Megatron has the Registry API for that.
    Then, put the code for changing the setting in the Form_Load, and to change it back, put the "change-back-code" in the Form_Unload.
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  3. #3
    Pirre001
    Guest
    Thanks for you info, CyberCarsten!

    Where can I find Megatron's info about that?
    I need help right now.

    Regards

  4. #4
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    I think there is a copy in the articles section. Look for 'Registry'. You could also try to search on the forums.
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  5. #5
    Pirre001
    Guest
    I have been looking, but I haven't found anything? Where?

    I saw that Megatron has posted over 6600 messages.
    I sent a E-Mail to him.

  6. #6
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  7. #7
    Pirre001
    Guest
    Thanks!

    I still do not understand how to do?

    I wanna change a setting temporary in Registry when i start a form. Then when I close the form the Settings will go back to default value.

    The changes I Wanna do when I start the form is this:

    \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.5\Engines\Text\

    Value name: Format
    Change Value Data to "TabDelimited"

  8. #8
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    in a module:

    Code:
    Private Const REG_OPTION_NON_VOLATILE = 0
    Private Const REG_SZ As Long = 1
    Private Const REG_BINARY = 3
    Private Const REG_DWORD As Long = 4
    
    Private Const READ_CONTROL = &H20000
    Private Const SYNCHRONIZE = &H100000
    Private Const KEY_ALL_ACCESS As Long = &H3F
    Private Const KEY_QUERY_VALUE As Long = &H1
    Private Const KEY_ENUMERATE_SUB_KEYS As Long = &H8
    Private Const KEY_NOTIFY As Long = &H10
    Private Const KEY_READ = ((READ_CONTROL Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
    
    Enum RegistryRootConstants
        HKEY_CLASSES_ROOT = &H80000000
        HKEY_CURRENT_USER = &H80000001
        HKEY_LOCAL_MACHINE = &H80000002
        HKEY_USERS = &H80000003
        HKEY_Performance_Data = &H80000004
        HKEY_CURRENT_CONFIG = &H80000005
        HKEY_DYN_DATA = &H80000006
    End Enum
    
    Private Const Error_NONE As Long = 0
    Private Const Error_BADDB As Long = 1
    Private Const Error_BADKEY As Long = 2
    Private Const Error_CANTOPEN As Long = 3
    Private Const Error_CANTREAD As Long = 4
    Private Const Error_CANTWRITE As Long = 5
    Private Const Error_OUTOFMEMORY As Long = 6
    Private Const Error_INVALID_PARAMETER As Long = 7
    Private Const Error_ACCESS_DENIED As Long = 8
    Private Const Error_INVALID_PARAMETERS As Long = 87
    Private Const Error_NO_MORE_ITEMS As Long = 259
    
    
    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 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 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, phkResult 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 RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    
    Public Sub SaveSetting(ByVal szRegistrySection As String, ByVal szRegistryKey As String, ByVal szRegistrySetting As String)
        Dim lReturnValue As Long
        Dim hKey As Long
    
        lReturnValue = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szRegistrySection, 0&, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0&, hKey, lReturnValue)
        lReturnValue = RegSetValueExString(hKey, szRegistryKey, 0&, REG_SZ, szRegistrySetting, Len(szRegistrySetting))
        RegCloseKey hKey
    End Sub
    
    
    Public Function GetSetting(ByVal szRegistrySection As String, ByVal szRegistryKey As String, ByVal szDefaultRegistrySetting As String) As String
        Dim szRegistrySetting As String
        Dim lReturnValue As Long
        Dim lData As Long
        Dim hKey As Long
    
        lReturnValue = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szRegistrySection, 0, KEY_READ, hKey)
        lReturnValue = RegQueryValueExNULL(hKey, szRegistryKey, 0&, REG_SZ, 0&, lData)
        
        szRegistrySetting = String(lData, 0)
        lReturnValue = RegQueryValueExString(hKey, szRegistryKey, 0&, REG_SZ, szRegistrySetting, lData)
        If lReturnValue = 0 Then
            szRegistrySetting = Left(szRegistrySetting, lData - 1)
        Else
            szRegistrySetting = szDefaultRegistrySetting
        End If
    
        RegCloseKey hKey
        
        GetSetting = szRegistrySetting
    End Function
    
    
    VBBrowser v2.2.4
    in form:

    Code:
    SaveSetting "SOFTWARE\Microsoft\Jet\3.5\Engines\Text\", "Format", "TabDelimited"
    VBBrowser v2.2.4
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  9. #9
    Pirre001
    Guest
    Now it works for me. When i start the form the value changes in Registry.
    But how do I make the code go back to the value it was before I start the form?

    I'm very greateful for your help!

  10. #10
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    in the unload event of the form:

    Private Sub Form_Unload()

    just call the savesetting again and put the other value back in.

    if the other value changes all the time then do this:

    in gen Dec section:

    Dim PrevValue as String

    in the form load:

    PrevValue = GetSetting ("SOFTWARE\Microsoft\Jet\3.5\Engines\Text\", "Format", "")

    (you can change the "" to something else...that is the default value..so if there is nothing there you can make it be something)

    then do the SaveSetting to the TabDelimited

    then in Unload:

    SaveSetting "SOFTWARE\Microsoft\Jet\3.5\Engines\Text\", "Format", PrevValue
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  11. #11
    Pirre001
    Guest
    Everything works now.

    Thank you,geoff_xrx!

  12. #12
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    you're Welcome
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

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