00236 :
00237
00238 This function queries
the value of a key.
00239
00240 Arguments:
00241
00242 KeyHandle -
Handle of a key opened
for GENERIC_READ access via
NtOpenKey.
00243
00244 KeyValueType - Optional pointer to variable that will receive
the
00245 client-defined
type of
the key value (
if any). If no value has been
00246 set
for the key, 0
is returned.
00247
00248 KeyValue - Optional pointer to buffer in which part or all of
the key's
00249 value (as set on the most recent call to NtSetValueKey) will be
00250 returned. If
the key's value
is too large to fit into
the supplied
00251 buffer, as much of
the value as will fit into
the buffer will be
00252 returned and
the warning STATUS_BUFFER_OVERFLOW
is returned. If no
00253 value has ever been set, nothing
is returned. If
NULL is specified
00254
for this parameter, no
Key Value
is returned.
00255
00256 KeyValueLength - On input,
this optional parameter points to a variable
00257 that contains
the length in bytes of
the KeyValue buffer (
if any). If
00258 no KeyValue buffer
is specified,
the variable content on entry
is
00259 ignored. On
return,
the referenced variable (
if any) receives
the
00260 FULL length in bytes of
the key value. If
the key's value
is too
00261 large to fit into
the supplied buffer, as much of
the value as will
00262 fit into
the buffer will be returned and
the warning
00263 STATUS_BUFFER_OVERFLOW
is returned.
00264
00265 The returned length
is intended
for use by calling code in allocating
00266 a buffer of sufficient size to hold
the key's value. After receiving
00267 STATUS_BUFFER_OVERFLOW from
NtQueryValueKey, calling code may make a
00268 subsequent call to
NtQueryValueKey with a buffer of size equal to
the
00269 length returned by
the prior call.
00270
00271 If no value has been set
for the key, 0
is returned.
00272
00273 LastWriteTime - Optional parameter to variable which receives a time stamp
00274 specifying
the last time that
the key was written.
00275
00276 Return Value:
00277
00278
NTSTATUS - Result code
00279
00280 STATUS_SUCCESS - Call was successful
00281
00282 STATUS_INVALID_PARAMETER - Invalid parameter
00283
00284 STATUS_ACCESS_DENIED - Caller does not have GENERIC_READ access to
00285
the specified key
00286
00287 STATUS_BUFFER_OVERFLOW - This
is a warning that
the key's value
00288
is too large
for the buffer specified by
the KeyValue and
00289 KeyValueLength parameters. Use
the length returned to
00290 determine
the size of buffer to allocate
for a subsequent
00291 call of
NtQueryValueKey.
00292
00293 --*/
00294
00295 {
00296
00297 UNICODE_STRING NullName;
00298
NTSTATUS Status;
00299 PKEY_VALUE_PARTIAL_INFORMATION ValueInformation;
00300 ULONG ValueLength;
00301
00302
RTL_PAGED_CODE();
00303
00304
00305
00306
00307
00308 ValueLength = 0;
00309
if (ARGUMENT_PRESENT(KeyValueLength)) {
00310 ValueLength = *KeyValueLength;
00311 }
00312
00313 ValueLength += FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
00314 ValueInformation =
RtlAllocateHeap(RtlProcessHeap(), 0, ValueLength);
00315
if (ValueInformation ==
NULL) {
00316
return STATUS_INSUFFICIENT_RESOURCES;
00317 }
00318
00319
00320
00321
00322
00323 NullName.Length = 0;
00324
Status =
NtQueryValueKey(KeyHandle,
00325 &NullName,
00326 KeyValuePartialInformation,
00327 ValueInformation,
00328 ValueLength,
00329 &ValueLength);
00330
00331
00332
00333
00334
00335
00336
if (
Status == STATUS_OBJECT_NAME_NOT_FOUND) {
00337
Status = STATUS_SUCCESS;
00338 ValueInformation->DataLength = 0;
00339 ValueInformation->Type = 0;
00340 }
00341
00342
00343
00344
00345
00346
if (
NT_SUCCESS(Status) || (
Status == STATUS_BUFFER_OVERFLOW)) {
00347
if (ARGUMENT_PRESENT(KeyValueLength)) {
00348 *KeyValueLength = ValueInformation->DataLength;
00349 }
00350
00351
if (ARGUMENT_PRESENT(KeyValueType)) {
00352 *KeyValueType = ValueInformation->Type;
00353 }
00354 }
00355
00356
00357
00358
00359
00360
00361
if (
NT_SUCCESS(Status) && ARGUMENT_PRESENT(KeyValue)) {
00362 RtlMoveMemory(KeyValue,
00363 &ValueInformation->Data[0],
00364 ValueInformation->DataLength);
00365 }
00366
00367
RtlFreeHeap(RtlProcessHeap(), 0, ValueInformation);
00368
return Status;
00369 }