Microsoft Office Tutorials and References
In Depth Information
Windows API Calls
(ByVal hKey As Long) As Long
Private Declare PtrSafe Function RegSetValueExA Lib “ADVAPI32.DLL” _
(ByVal hKey As Long, ByVal sValueName As String, _
ByVal dwReserved As Long, ByVal dwType As Long, _
ByVal sValue As String, ByVal dwSize As Long) As Long
Private Declare PtrSafe Function RegCreateKeyA Lib “ADVAPI32.DLL” _
(ByVal hKey As Long, ByVal sSubKey As String, _
ByRef hkeyResult As Long) As Long
Private Declare PtrSafe Function RegQueryValueExA Lib “ADVAPI32.DLL” _
(ByVal hKey As Long, ByVal sValueName As String, _
ByVal dwReserved As Long, ByRef lValueType As Long, _
ByVal sValue As String, ByRef lResultLen As Long) As Long
I developed two wrapper functions that simplify the task of working with the Registry:
GetRegistry and WriteRegistry . These functions are available on the companion
CD-ROM in a file named windows registry.xlsm . This workbook includes a
procedure that demonstrates reading from the Registry and writing to the Registry.
Reading from the Registry
The GetRegistry function returns a setting from the specified location in the Registry. It takes
three arguments:
h RootKey : A string that represents the branch of the Registry to address. This string can
be one of the following:
HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
HKEY_CURRENT_CONFIG
h Path : The full path of the Registry category being addressed.
h RegEntry : The name of the setting to retrieve.
Here’s an example. If you’d like to find which graphic file, if any, is being used for the desktop
wallpaper, you can call GetRegistry as follows. (Notice that the arguments aren’t case-sensitive.)
RootKey = “hkey_current_user”
Path = “Control Panel\Desktop”
RegEntry = “Wallpaper”
MsgBox GetRegistry(RootKey, Path, RegEntry), _
vbInformation, Path & “\RegEntry”
 
Search JabSto ::




Custom Search