2 * COPYRIGHT: GPL, see COPYING in the top level directory
3 * PROJECT: ReactOS win32 kernel mode subsystem server
4 * PURPOSE: Registry loading and storing
5 * FILE: subsystem/win32/win32k/misc/registry.c
6 * PROGRAMER: Timo Kreuzer (timo.kreuzer@reactos.org)
17 IN PCWSTR pwszKeyName
,
18 IN PCWSTR pwszValueName
,
24 OBJECT_ATTRIBUTES ObjectAttributes
;
25 UNICODE_STRING usCurrentUserKey
, usKeyName
, usValueName
;
26 WCHAR awcBuffer
[MAX_PATH
];
28 PKEY_VALUE_PARTIAL_INFORMATION pInfo
;
29 ULONG cbInfoSize
, cbReqSize
;
31 /* Get the path of the current user's profile */
32 Status
= RtlFormatCurrentUserKeyPath(&usCurrentUserKey
);
33 if (!NT_SUCCESS(Status
))
38 /* Initialize empty key name */
39 RtlInitEmptyUnicodeString(&usKeyName
, awcBuffer
, sizeof(awcBuffer
));
41 /* Append the current user key name */
42 Status
= RtlAppendUnicodeStringToString(&usKeyName
, &usCurrentUserKey
);
44 /* Free the current user key name */
45 RtlFreeUnicodeString(&usCurrentUserKey
);
47 /* Check for success */
48 if (!NT_SUCCESS(Status
))
53 /* Append a '\', we can trust in enough space left. */
54 usKeyName
.Buffer
[usKeyName
.Length
/ sizeof(WCHAR
)] = '\\';
55 usKeyName
.Length
+= sizeof(WCHAR
);
57 /* Append the subkey name */
58 Status
= RtlAppendUnicodeToString(&usKeyName
, pwszKeyName
);
59 if (!NT_SUCCESS(Status
))
64 /* Initialize object attributes */
65 InitializeObjectAttributes(&ObjectAttributes
,
72 Status
= ZwOpenKey(&hkey
, KEY_READ
, &ObjectAttributes
);
73 if (!NT_SUCCESS(Status
))
78 /* Check if the local buffer is sufficient */
79 cbInfoSize
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) + cbDataSize
;
80 if (cbInfoSize
<= sizeof(awcBuffer
))
82 pInfo
= (PVOID
)awcBuffer
;
86 /* It's not, allocate a sufficient buffer */
87 pInfo
= ExAllocatePoolWithTag(PagedPool
, cbInfoSize
, TAG_TEMP
);
96 RtlInitUnicodeString(&usValueName
, pwszValueName
);
97 Status
= ZwQueryValueKey(hkey
,
99 KeyValuePartialInformation
,
103 if (NT_SUCCESS(Status
))
105 /* Did we get the right type */
106 if (pInfo
->Type
== ulType
)
108 /* Copy the contents to the caller */
109 RtlCopyMemory(pvData
, pInfo
->Data
, cbDataSize
);
115 if (pInfo
!= (PVOID
)awcBuffer
)
116 ExFreePoolWithTag(pInfo
, TAG_TEMP
);
118 return NT_SUCCESS(Status
);
124 IN PCWSTR pwszKeyName
,
125 IN PCWSTR pwszValueName
,
131 OBJECT_ATTRIBUTES ObjectAttributes
;
132 UNICODE_STRING usCurrentUserKey
, usKeyName
, usValueName
;
133 WCHAR awcBuffer
[MAX_PATH
];
136 // FIXME: logged in user versus current process user?
137 /* Get the path of the current user's profile */
138 Status
= RtlFormatCurrentUserKeyPath(&usCurrentUserKey
);
139 if (!NT_SUCCESS(Status
))
141 DPRINT1("RtlFormatCurrentUserKeyPath failed\n");
145 /* Initialize empty key name */
146 RtlInitEmptyUnicodeString(&usKeyName
, awcBuffer
, sizeof(awcBuffer
));
148 /* Append the current user key name */
149 Status
= RtlAppendUnicodeStringToString(&usKeyName
, &usCurrentUserKey
);
150 if (!NT_SUCCESS(Status
))
155 /* Free the current user key name */
156 RtlFreeUnicodeString(&usCurrentUserKey
);
158 /* Append a '\', we can trust in enough space left. */
159 usKeyName
.Buffer
[usKeyName
.Length
/ sizeof(WCHAR
)] = '\\';
160 usKeyName
.Length
+= sizeof(WCHAR
);
162 /* Append the subkey name */
163 Status
= RtlAppendUnicodeToString(&usKeyName
, pwszKeyName
);
164 if (!NT_SUCCESS(Status
))
166 DPRINT1("RtlAppendUnicodeToString failed with Status=%lx, buf:%d,%d\n", Status
, usKeyName
.Length
, usKeyName
.MaximumLength
);
170 /* Initialize object attributes */
171 InitializeObjectAttributes(&ObjectAttributes
,
173 OBJ_CASE_INSENSITIVE
,
177 /* Open or create the key */
178 Status
= ZwCreateKey(&hkey
,
179 KEY_READ
| KEY_WRITE
,
185 if(!NT_SUCCESS(Status
))
187 DPRINT1("Failed to create key: 0x%x\n", Status
);
191 /* Initialize the value name string */
192 RtlInitUnicodeString(&usValueName
, pwszValueName
);
194 Status
= ZwSetValueKey(hkey
, &usValueName
, 0, ulType
, pvData
, cbDataSize
);
195 if(!NT_SUCCESS(Status
))
197 DPRINT1("Failed to write reg key '%S' value '%S', Status = %lx\n",
198 pwszKeyName
, pwszValueName
, Status
);
204 return NT_SUCCESS(Status
);