1 | // ********************************************************************************************************************************************************
|
---|
2 | // Aplicación HIDRA
|
---|
3 | // Copyright 2003-2005 José Manuel Alonso. Todos los derechos reservados.
|
---|
4 | // Fichero: registro.c
|
---|
5 | // Descripción:
|
---|
6 | // Este proyecto implementa el servicio hidra en un ordenador con plataforma windows NT. Este fichero aporta las funciones de
|
---|
7 | // manipulación del registro de Windows
|
---|
8 | // *********************************************************************************************************************************************************
|
---|
9 | #include "registrow.h"
|
---|
10 | //____________________________________________________________________________________________________________________________
|
---|
11 | //
|
---|
12 | BOOLEAN WriteRegistryString(HKEY hive,char *key,char *subkey,char *value)
|
---|
13 | {
|
---|
14 | HKEY hk;
|
---|
15 | DWORD dp,ret;
|
---|
16 | int sz;
|
---|
17 |
|
---|
18 | sz=strlen(value)+1;
|
---|
19 | if (RegCreateKeyEx(
|
---|
20 | hive,
|
---|
21 | key,
|
---|
22 | 0,
|
---|
23 | "REG_SZ",
|
---|
24 | REG_OPTION_NON_VOLATILE,
|
---|
25 | KEY_WRITE,
|
---|
26 | NULL,
|
---|
27 | &hk,
|
---|
28 | &dp)!=ERROR_SUCCESS)
|
---|
29 | return FALSE;
|
---|
30 | if ((ret=RegSetValueEx(hk,subkey,0,REG_SZ,(unsigned char *)value,sz))!=ERROR_SUCCESS)
|
---|
31 | {
|
---|
32 | SetLastError(ret);
|
---|
33 | return FALSE;
|
---|
34 | }
|
---|
35 | RegCloseKey(hk);
|
---|
36 | return TRUE;
|
---|
37 | }
|
---|
38 | // _____________________________________________________________________________________________________________
|
---|
39 | BOOLEAN WriteRegistryBytes(HKEY hive,char *key,char *subkey,void *value,int sz)
|
---|
40 | {
|
---|
41 | HKEY hk;
|
---|
42 | DWORD dp,ret;
|
---|
43 |
|
---|
44 | if (RegCreateKeyEx(
|
---|
45 | hive,
|
---|
46 | key,
|
---|
47 | 0,
|
---|
48 | "REG_BINARY",
|
---|
49 | REG_OPTION_NON_VOLATILE,
|
---|
50 | KEY_WRITE,
|
---|
51 | NULL,
|
---|
52 | &hk,
|
---|
53 | &dp)!=ERROR_SUCCESS)
|
---|
54 | return FALSE;
|
---|
55 | if ((ret=RegSetValueEx(hk,subkey,0,REG_BINARY,(BYTE*)value,sz))!=ERROR_SUCCESS)
|
---|
56 | {
|
---|
57 | SetLastError(ret);
|
---|
58 | return FALSE;
|
---|
59 | }
|
---|
60 | RegCloseKey(hk);
|
---|
61 | return TRUE;
|
---|
62 | }
|
---|
63 | // _____________________________________________________________________________________________________________
|
---|
64 | BOOLEAN WriteRegistryInteger(HKEY hive,char *key,char *subkey,DWORD value)
|
---|
65 | {
|
---|
66 | HKEY hk;
|
---|
67 | DWORD dp,ret;
|
---|
68 | int sz;
|
---|
69 |
|
---|
70 | sz=sizeof(DWORD);
|
---|
71 | if (RegCreateKeyEx(
|
---|
72 | hive,
|
---|
73 | key,
|
---|
74 | 0,
|
---|
75 | "REG_DWORD",
|
---|
76 | REG_OPTION_NON_VOLATILE,
|
---|
77 | KEY_WRITE,
|
---|
78 | NULL,
|
---|
79 | &hk,
|
---|
80 | &dp)!=ERROR_SUCCESS)
|
---|
81 | return FALSE;
|
---|
82 | if ((ret=RegSetValueEx(hk,subkey,0,REG_DWORD,(BYTE*)&value,sz))!=ERROR_SUCCESS)
|
---|
83 | {
|
---|
84 | SetLastError(ret);
|
---|
85 | return FALSE;
|
---|
86 | }
|
---|
87 | RegCloseKey(hk);
|
---|
88 | return TRUE;
|
---|
89 | }
|
---|
90 | // _____________________________________________________________________________________________________________
|
---|
91 | BOOLEAN ReadRegistryString(HKEY hive,char *key,char *subkey,char *value,int sz)
|
---|
92 | {
|
---|
93 | HKEY hk;
|
---|
94 | DWORD type,ret;
|
---|
95 |
|
---|
96 | if (RegOpenKeyEx(
|
---|
97 | hive,
|
---|
98 | key,
|
---|
99 | 0,
|
---|
100 | KEY_QUERY_VALUE,
|
---|
101 | &hk)!=ERROR_SUCCESS)
|
---|
102 | {
|
---|
103 | return FALSE;
|
---|
104 | }
|
---|
105 | if ((ret=RegQueryValueEx(hk,subkey,0,&type,(unsigned char *)value,(DWORD*)&sz))!=ERROR_SUCCESS)
|
---|
106 | {
|
---|
107 | RegCloseKey(hk);
|
---|
108 | SetLastError(ret);
|
---|
109 | return FALSE;
|
---|
110 | }
|
---|
111 | RegCloseKey(hk);
|
---|
112 | return TRUE;
|
---|
113 | }
|
---|
114 | // _____________________________________________________________________________________________________________
|
---|
115 | BOOLEAN ReadRegistryInteger(HKEY hive,char *key,char *subkey,DWORD *value)
|
---|
116 | {
|
---|
117 | HKEY hk;
|
---|
118 | DWORD sz=sizeof(DWORD),type,ret;
|
---|
119 |
|
---|
120 | if (RegOpenKeyEx(
|
---|
121 | hive,
|
---|
122 | key,
|
---|
123 | 0,
|
---|
124 | KEY_QUERY_VALUE,
|
---|
125 | &hk)!=ERROR_SUCCESS)
|
---|
126 | {
|
---|
127 | return FALSE;
|
---|
128 | }
|
---|
129 | if ((ret=RegQueryValueEx(hk,subkey,0,&type,(LPBYTE)value,&sz))!=ERROR_SUCCESS)
|
---|
130 | {
|
---|
131 | RegCloseKey(hk);
|
---|
132 | SetLastError(ret);
|
---|
133 | return FALSE;
|
---|
134 | }
|
---|
135 | RegCloseKey(hk);
|
---|
136 | return TRUE;
|
---|
137 | }
|
---|
138 | // _____________________________________________________________________________________________________________
|
---|
139 | BOOLEAN ReadRegistryShort(HKEY hive,char *key,char *subkey,short *value)
|
---|
140 | {
|
---|
141 | HKEY hk;
|
---|
142 | DWORD sz=sizeof(DWORD),type,tmpvalue,ret;
|
---|
143 |
|
---|
144 | if (RegOpenKeyEx(
|
---|
145 | hive,
|
---|
146 | key,
|
---|
147 | 0,
|
---|
148 | KEY_QUERY_VALUE,
|
---|
149 | &hk)!=ERROR_SUCCESS)
|
---|
150 | {
|
---|
151 | return FALSE;
|
---|
152 | }
|
---|
153 | if ((ret=RegQueryValueEx(hk,subkey,0,&type,(LPBYTE)&tmpvalue,&sz))!=ERROR_SUCCESS)
|
---|
154 | {
|
---|
155 | RegCloseKey(hk);
|
---|
156 | SetLastError(ret);
|
---|
157 | return FALSE;
|
---|
158 | }
|
---|
159 | RegCloseKey(hk);
|
---|
160 | *value=(short)tmpvalue;
|
---|
161 | return TRUE;
|
---|
162 | }
|
---|
163 | // _____________________________________________________________________________________________________________
|
---|
164 | BOOLEAN DeleteRegistryValue(HKEY hive,char *key,char *subkey)
|
---|
165 | {
|
---|
166 | HKEY hk;
|
---|
167 | DWORD ret;
|
---|
168 |
|
---|
169 | if (RegOpenKeyEx(
|
---|
170 | hive,
|
---|
171 | key,
|
---|
172 | 0,
|
---|
173 | KEY_SET_VALUE,
|
---|
174 | &hk)!=ERROR_SUCCESS)
|
---|
175 | {
|
---|
176 | return FALSE;
|
---|
177 | }
|
---|
178 | if ((ret=RegDeleteValue(hk,subkey))!=ERROR_SUCCESS)
|
---|
179 | {
|
---|
180 | RegCloseKey(hk);
|
---|
181 | SetLastError(ret);
|
---|
182 | return FALSE;
|
---|
183 | }
|
---|
184 | RegCloseKey(hk);
|
---|
185 | return TRUE;
|
---|
186 | }
|
---|
187 | // _____________________________________________________________________________________________________________
|
---|
188 | BOOLEAN DeleteRegistryKey(HKEY hive,char *key)
|
---|
189 | {
|
---|
190 | DWORD ret;
|
---|
191 |
|
---|
192 | if ((ret=RegDeleteKey(hive,key))!=ERROR_SUCCESS)
|
---|
193 | {
|
---|
194 | SetLastError(ret);
|
---|
195 | return FALSE;
|
---|
196 | }
|
---|
197 | return TRUE;
|
---|
198 | }
|
---|
199 |
|
---|