Module RegistryAPI.pkg
1// RegistryAPI.pkg
2// Author: SWB
3Use LanguageText.pkg
4Use Dll.pkg
5Use DFTypes.pkg
6Use WinKern.pkg
7
8// These are the key root values.
9Define HKEY_CLASSES_ROOT for |CI$80000000
10Define HKEY_CURRENT_USER for |CI$80000001
11Define HKEY_LOCAL_MACHINE for |CI$80000002
12Define HKEY_USERS for |CI$80000003
13Define HKEY_PERFORMANCE_DATA for |CI$80000004
14Define HKEY_CURRENT_CONFIG for |CI$80000005
15Define HKEY_DYN_DATA for |CI$80000006
16
17Define KEY_QUERY_VALUE for |CI$0001
18Define KEY_SET_VALUE for |CI$0002
19Define KEY_CREATE_SUB_KEY for |CI$0004
20Define KEY_ENUMERATE_SUB_KEYS for |CI$0008
21Define KEY_NOTIFY for |CI$0010
22Define KEY_CREATE_LINK for |CI$0020
23
24Define READ_CONTROL for |CI$00020000
25Define WRITE_DAC for |CI$00040000
26Define WRITE_OWNER for |CI$00080000
27Define SYNCHRONIZE for |CI$00100000
28Define NOTSYNCHRONIZE for |CI$FFEFFFFF // This one made up for ease of use
29
30Define STANDARD_RIGHTS_REQUIRED for |CI$000F0000
31Define STANDARD_RIGHTS_READ for READ_CONTROL
32Define STANDARD_RIGHTS_WRITE for READ_CONTROL
33Define STANDARD_RIGHTS_EXECUTE for READ_CONTROL
34Define STANDARD_RIGHTS_ALL for |CI$001F0000
35Define SPECIFIC_RIGHTS_ALL for |CI$0000FFFF
36
37Define KEY_READ for ((STANDARD_RIGHTS_READ ior KEY_QUERY_VALUE ior KEY_ENUMERATE_SUB_KEYS ior KEY_NOTIFY) IAND (NOTSYNCHRONIZE))
38Define KEY_WRITE for ((STANDARD_RIGHTS_WRITE ior KEY_SET_VALUE ior KEY_CREATE_SUB_KEY) iand (NOTSYNCHRONIZE))
39Define KEY_EXECUTE for ((KEY_READ) iand (NOTSYNCHRONIZE))
40Define KEY_ALL_ACCESS for ((STANDARD_RIGHTS_ALL ior KEY_QUERY_VALUE ior KEY_SET_VALUE ior KEY_CREATE_SUB_KEY ior KEY_ENUMERATE_SUB_KEYS ior KEY_NOTIFY ior KEY_CREATE_LINK) IAND (NOTSYNCHRONIZE))
41
42// Predefined Value Types.
43Define REG_NONE for 0 // No value type
44Define REG_SZ for 1 // Unicode nul terminated string
45Define REG_EXPAND_SZ for 2 // Unicode nul terminated string (WITH ENVIRONMENT VARIABLE REFERENCES)
46Define REG_BINARY for 3 // Free form binary
47Define REG_DWORD for 4 // 32-bit number
48Define REG_DWORD_LITTLE_ENDIAN for 4 // 32-bit number (same as REG_DWORD)
49Define REG_DWORD_BIG_ENDIAN for 5 // 32-bit number
50Define REG_LINK for 6 // Symbolic Link (unicode)
51Define REG_MULTI_SZ for 7 // Multiple Unicode strings
52Define REG_RESOURCE_LIST for 8 // Resource list in the resource map
53Define REG_FULL_RESOURCE_DESCRIPTOR for 9 // Resource list in the hardware description
54Define REG_RESOURCE_REQUIREMENTS_LIST for 10
55
56// Open/Create Options
57Define REG_OPTION_RESERVED for 0 // Parameter is reserved
58Define REG_OPTION_NON_VOLATILE for 0 // Key is preserved when system is rebooted
59Define REG_OPTION_VOLATILE for 1 // Key is not preserved when system is rebooted
60Define REG_OPTION_CREATE_LINK for 2 // Created key is a symbolic link
61Define REG_OPTION_BACKUP_RESTORE for 4 // open for backup or restore special access rules privilege required
62Define REG_OPTION_OPEN_LINK for 8 // Open symbolic link
63Define REG_LEGAL_OPTION for (REG_OPTION_RESERVED ior REG_OPTION_NON_VOLATILE ior REG_OPTION_VOLATILE ior REG_OPTION_CREATE_LINK ior REG_OPTION_BACKUP_RESTORE ior REG_OPTION_OPEN_LINK)
64
65// Key creation/open disposition
66Define REG_CREATED_NEW_KEY for 1 // New Registry Key created
67Define REG_OPENED_EXISTING_KEY for 2 // Existing Key opened
68
69External_Function RegOpenKeyEx "RegOpenKeyExA" AdvApi32.dll ;
70 Handle hKey String sSubKey DWord ulOptions DWord samDesired Pointer lphKey ;
71 Returns Dword
72
73External_Function RegCloseKey "RegCloseKey" AdvApi32.dll ;
74 Handle hKey ;
75 Returns DWord
76
77External_Function RegEnumKeyEx "RegEnumKeyExA" AdvApi32.dll ;
78 Handle hKey Dword dwIndex Pointer lpsName Pointer lpcbName ;
79 Pointer lpReserved Pointer lpClass Pointer lpcbClass Pointer pTime ;
80 Returns DWord
81
82External_Function RegSetValueEx "RegSetValueExA" AdvApi32.dll ;
83 Handle hKey String sValueName Dword dwReserved Dword dwType Pointer lpsData Dword cbData ;
84 Returns Dword
85
86External_Function RegQueryValueEx "RegQueryValueExA" AdvApi32.dll ;
87 Handle hKey String sValueName Pointer lpReserved Pointer lpsDwType Pointer lpsData Pointer lpcbData ;
88 Returns Dword
89
90External_Function RegCreateKeyEx "RegCreateKeyExA" AdvApi32.dll ;
91 Handle hKey ; // handle to open key
92 String lpSubKey ; // subkey name
93 DWord Reserved ; // reserved
94 String lpClass ; // class string
95 DWord dwOptions ; // special options flag
96 DWord samDesired ; // desired security access
97 Pointer lpSecurityAttributes ;
98 Pointer phkResult ; // receives opened handle
99 Pointer lpdwDisposition ; // disposition value buffer
100Returns Integer
101
102External_Function ShDeleteKey "SHDeleteKeyA" Shlwapi.dll Handle hKey String sKey Returns Integer
103
104External_Function RegDeleteValue "RegDeleteValueA" AdvApi32.dll Handle hKey String sKey Returns Integer
105
106External_Function RegEnumValue "RegEnumValueA" AdvApi32.dll ;
107 Handle hKey; // handle to key to query
108 DWord dwIndex; // index of value to query
109 Pointer lpValueName; // buffer for value string
110 Pointer lpcbValueName; // size of value buffer
111 Pointer lpReserved; // reserved
112 Pointer lpType; // buffer for type code
113 Pointer lpData; // buffer for value data
114 Pointer lpcbData; // size of data buffer
115Returns Integer // WINERROR
116
117External_Function RegEnumKey "RegEnumKeyEx" AdvApi32.dll ;
118 Handle hKey ; // handle to key to enumerate
119 DWord dwIndex ; // index of subkey to enumerate
120 Pointer lpName ; // address of buffer for subkey name
121 Pointer lpcbName ; // address for size of subkey buffer
122 Pointer lpReserved ; // reserved
123 Pointer lpClass ; // address of buffer for class string
124 Pointer lpcbClass ; // address for size of class buffer
125 Pointer lpftLastWriteTime ; // address for time key last written to
126Returns Integer // WINERROR
127
128External_Function RegQueryInfoKey "RegQueryInfoKeyA" AdvApi32.dll ;
129 Handle hKey ; // handle to key to query
130 Pointer lpClass ; // buffer for class string
131 Pointer lpcbClass ; // size of class string buffer
132 Pointer lpReserved ; // reserved
133 Pointer lpcSubKeys ; // number of subkeys
134 Pointer lpcbMaxSubKeyLen ; // longest subkey name length
135 Pointer lpcbMaxClassLen ; // longest class string length
136 Pointer lpcValues ; // number of value entries
137 Pointer lpcbMaxValueNameLen ; // longest value name length
138 Pointer lpcbMaxValueLen ; // longest value data length
139 Pointer lpcbSecurityDescriptor ; // descriptor length
140 Pointer lpftLastWriteTime ; // last write time
141Returns Integer // WINERROR
142
143External_Function RegFlushKey "RegFlushKey" AdvApi32.dll ;
144 Handle hKey ;
145 Returns DWord
146
147Type tFileTime
148 Field tFileTime.dwLowDateTime as DWord
149 Field tFileTime.dwHighDateTime as DWord
150End_Type
151
152Type tRegKeyInfo
153 Field tRegKeyInfo.NumSubKeys as Integer
154 Field tRegKeyInfo.MaxSubKeyLen as Integer
155 Field tRegKeyInfo.NumValues as Integer
156 Field tRegKeyInfo.MaxValueLen as Integer
157 Field tRegKeyInfo.MaxDataLen as Integer
158 Field tRegKeyInfo.FileTime.dwLowDateTime as DWord
159 Field tRegKeyInfo.FileTime.dwHighDateTime as DWord
160End_Type
161
162Function FormatWinError Global Integer iError Returns String
163 Integer iFlags iBytes iResult
164 Pointer pAddress
165 String sBuffer
166
167 // Initialize pAddress, just to make sure AddressOf() works
168 Move 0 To pAddress
169
170 // Set the flags...
171 Move (FORMAT_MESSAGE_ALLOCATE_BUFFER iOr FORMAT_MESSAGE_FROM_SYSTEM iOr FORMAT_MESSAGE_IGNORE_INSERTS) To iFlags
172
173 // If FormatMessage fails iBytes will be 0, therefore no bytes will be copied and the error will only
174 // display the error code returned from GetLastError...
175 Move (FormatMessage(iFlags,0,iError,0,AddressOf(pAddress),0,0)) To iBytes
176
177 // Allocate the buffer...
178 Move (Repeat(Character(0),iBytes)) To sBuffer
179 If (iBytes > 0) Move (CopyMemory(AddressOf(sBuffer),pAddress,iBytes)) To iResult
180
181 // Display the error code and message, if no message is available use 'No error text available'.
182 If (Trim(sBuffer) = "") Move C_$NoErrorTextAvailable To sBuffer
183 //Error 9999 ("("+String(iError)+") "+sBuffer)
184 //Error 9999 ('Windows has reported the following Error:' +character(13)+Character(13) +sBuffer +character(13) +'(Windows Error Code=' +String(iError) +')')
185
186 // Free memory used by the buffer...
187 Move (Free(pAddress)) To iResult
188 Function_Return (sBuffer +" (" +C_$ErrorCode +"=" +String(iError) +")")
189End_Function // FormatWinError
190
191
192