|
-
Jul 16th, 2002, 09:01 PM
#1
Thread Starter
Fanatic Member
Saving to registry..........
I need to save some very simple things in my program to the registry. Can someone post a short example of how to Read and write to the windows registry? Also, are there any differences with this in Windows XP? All I need to save is whether or not a a checkbox is checked or not. Then when I load the program get the registery setting and set the checkbox value to that. To be honest, I don't need to save settings much in the small apps I make, and I have forgotten how to do this! I had a module of how to use Get & Save setting in one of my programs, but it was lost when I cleaned up my system and upgraded to Win XP. Any example appreciated.
-
Jul 16th, 2002, 09:06 PM
#2
-
Jul 17th, 2002, 06:14 AM
#3
SaveSetting and GetSetting are the most commonly used. They are limited in scope, however. Here is an example of reading a registry key using a copy of the Registry APIs. For more examples, down load the free API Viewer from http://www.allapi.net
VB Code:
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
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 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
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Sub Command1_Click()
Dim Result As Long
Dim KeyRet As Long
Dim KeyToRead As String
Dim KeyValue As String
Dim Length As Long
Result = RegOpenKey(HKEY_CURRENT_USER, "Software\KPD-Team\APIViewer 2001\", KeyRet)
KeyToRead = "MSDN"
Result = RegQueryValueEx(KeyRet, KeyToRead, 0, 0, "", Length)
KeyValue = Space$(Length - 1)
Result = RegQueryValueEx(KeyRet, KeyToRead, 0, 0, ByVal KeyValue, Length)
MsgBox KeyValue
RegCloseKey KeyRet
End Sub
-
Apr 15th, 2006, 03:24 AM
#4
Frenzied Member
Re: Saving to registry..........
Hack could u tell me if i can use your code to put read/write option to my vb6 application. could u explain to me where i can get the module for it. Api viewer dowload section has many thigns to downlod . which one do i need? thanks
-
Apr 15th, 2006, 03:29 AM
#5
Fanatic Member
Re: Saving to registry..........
without API:
VB Code:
'save to registry
'chkAutoCapsLock is a checkbox and im saving its value in the reg
'u can put this in a command button click event
SaveSetting "mySchool", "Settings", "AutoCaps", chkAutoCapsLock
to get the value and assign to checkbox:
VB Code:
Sub GetSettings()
On Error GoTo HELL
chkAutoCapsLock = CInt(GetSetting("mySchool", "Settings", "AutoCaps", "0"))
GoTo CleanUp
HELL:
WriteError Err.Number, Err.Description, Date, Me.Name, "GetSettings"
CleanUp:
End Sub
form the MSDN:
GetSetting Function
Returns a key setting value from an application's entry in the Windowsregistry.
Syntax
GetSetting(appname, section, key[, default])
The GetSetting function syntax has thesenamed arguments:
Part Description
appname Required.String expression containing the name of the application or project whose key setting is requested.
section Required. String expression containing the name of the section where the key setting is found.
key Required. String expression containing the name of the key setting to return.
default Optional.Expression containing the value to return if no value is set in the key setting. If omitted, default is assumed to be a zero-length string ("").
Remarks
If any of the items named in the GetSetting arguments do not exist, GetSetting returns the value of default.
SaveSetting Statement
Saves or creates an application entry in the application's entry in the Windowsregistry.
Syntax
SaveSetting appname, section, key, setting
The SaveSetting statement syntax has thesenamed arguments:
Part Description
appname Required.String expression containing the name of the application orproject to which the setting applies.
section Required. String expression containing the name of the section where the key setting is being saved.
key Required. String expression containing the name of the key setting being saved.
setting Required.Expression containing the value that key is being set to.
Remarks
An error occurs if the key setting can’t be saved for any reason.
On Error GoTo Hell
Hell:
Kill Me
Food For Thought:
- Do not judge a book... if you're not a judge!

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|