Added value delete and enumerate tests.

svn path=/trunk/; revision=4142
This commit is contained in:
Eric Kohl 2003-02-12 18:56:49 +00:00
parent 9895df9741
commit bd0f683f94

View file

@ -83,9 +83,9 @@ void CreateKeyTest(void)
void DeleteKeyTest(void) void DeleteKeyTest(void)
{ {
HKEY hKey;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName; UNICODE_STRING KeyName;
HKEY hKey;
NTSTATUS Status; NTSTATUS Status;
dprintf("Delete key '\\Registry\\Machine\\Software\\testkey':\n"); dprintf("Delete key '\\Registry\\Machine\\Software\\testkey':\n");
@ -252,7 +252,7 @@ void SetValueTest2(void)
RtlInitUnicodeStringFromLiteral(&ValueName, RtlInitUnicodeStringFromLiteral(&ValueName,
L"TestValue"); L"TestValue");
dprintf("NtSetValueKey: "); dprintf("NtSetValueKey:\n");
Status = NtSetValueKey(hKey, Status = NtSetValueKey(hKey,
&ValueName, &ValueName,
0, 0,
@ -265,6 +265,105 @@ void SetValueTest2(void)
} }
void DeleteValueTest(void)
{
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName;
UNICODE_STRING ValueName;
HKEY KeyHandle;
NTSTATUS Status;
dprintf("Open key: '\\Registry\\Machine\\Software\\testkey':\n");
RtlInitUnicodeStringFromLiteral(&KeyName,
L"\\Registry\\Machine\\Software\\testkey");
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status=NtOpenKey(&KeyHandle,
MAXIMUM_ALLOWED,
&ObjectAttributes);
dprintf(" Status = %lx\n", Status);
if (!NT_SUCCESS(Status))
return;
dprintf("Delete value:\n");
RtlInitUnicodeStringFromLiteral(&ValueName,
L"TestValue");
Status = NtDeleteValueKey(KeyHandle,
&ValueName);
dprintf(" Status = %lx\n", Status);
dprintf("Close key:\n");
Status = NtClose(KeyHandle);
dprintf(" Status = %lx\n", Status);
}
void EnumerateValueTest(void)
{
KEY_VALUE_FULL_INFORMATION KeyValueInformation[5];
KEY_BASIC_INFORMATION KeyInformation[5];
OBJECT_ATTRIBUTES ObjectAttributes;
UNICODE_STRING KeyName;
ULONG Index,Length,i;
HKEY hKey = NULL;
NTSTATUS Status;
dprintf("Open key: '\\Registry\\Machine\\Software\\testkey':\n");
RtlInitUnicodeStringFromLiteral(&KeyName,
L"\\Registry\\Machine\\Software\\testkey");
InitializeObjectAttributes(&ObjectAttributes,
&KeyName,
OBJ_CASE_INSENSITIVE,
NULL,
NULL);
Status=NtOpenKey(&hKey,
MAXIMUM_ALLOWED,
&ObjectAttributes);
dprintf(" Status = %lx\n", Status);
if (!NT_SUCCESS(Status))
return;
dprintf("Enumerate values: \n");
Index = 0;
while (Status == STATUS_SUCCESS)
{
Status = NtEnumerateValueKey(hKey,
Index++,
KeyValueFullInformation,
&KeyValueInformation[0],
sizeof(KeyValueInformation),
&Length);
if (Status == STATUS_SUCCESS)
{
dprintf(" Value:DO=%d, DL=%d, NL=%d, Name = ",
KeyValueInformation[0].DataOffset,
KeyValueInformation[0].DataLength,
KeyValueInformation[0].NameLength);
for (i = 0; i < KeyValueInformation[0].NameLength / 2; i++)
dprintf("%C", KeyValueInformation[0].Name[i]);
dprintf(", Type = %d\n", KeyValueInformation[0].Type);
if (KeyValueInformation[0].Type == REG_SZ)
dprintf(" Value = %S\n",
((char*)&KeyValueInformation[0]+KeyValueInformation[0].DataOffset));
if (KeyValueInformation[0].Type == REG_DWORD)
dprintf(" Value = %X\n",
*((DWORD*)((char*)&KeyValueInformation[0]+KeyValueInformation[0].DataOffset)));
}
}
dprintf("NtClose:\n");
Status = NtClose(hKey);
dprintf(" Status = %lx\n", Status);
}
void test1(void) void test1(void)
{ {
HKEY hKey = NULL, hKey1; HKEY hKey = NULL, hKey1;
@ -962,6 +1061,7 @@ void test9(void)
dprintf("%C",KeyInformation[0].Name[i]); dprintf("%C",KeyInformation[0].Name[i]);
dprintf("\n"); dprintf("\n");
} }
dprintf("NtEnumerateKey : \n"); dprintf("NtEnumerateKey : \n");
Index = 0; Index = 0;
while (Status == STATUS_SUCCESS) { while (Status == STATUS_SUCCESS) {
@ -1064,10 +1164,8 @@ int main(int argc, char* argv[])
dprintf(" 3 = Enumerate key\n"); dprintf(" 3 = Enumerate key\n");
dprintf(" 4 = Set value (REG_SZ)\n"); dprintf(" 4 = Set value (REG_SZ)\n");
dprintf(" 5 = Set value (REG_DWORD)\n"); dprintf(" 5 = Set value (REG_DWORD)\n");
// dprintf(" 6 = Enumerate value\n"); dprintf(" 6 = Delete value\n");
// dprintf(" 7=Registry link delete test\n"); dprintf(" 7 = Enumerate value\n");
// dprintf(" 8=Not available\n");
// dprintf(" 9=Ntxx read tcp/ip key test\n");
ReadConsoleA(InputHandle, Buffer, 3, &Result, NULL) ; ReadConsoleA(InputHandle, Buffer, 3, &Result, NULL) ;
switch (Buffer[0]) switch (Buffer[0])
{ {
@ -1093,27 +1191,15 @@ int main(int argc, char* argv[])
case '5': case '5':
SetValueTest2(); SetValueTest2();
break; break;
#if 0
case '6': case '6':
test6(); DeleteValueTest();
break; break;
#endif
#if 0
case '7': case '7':
test7(); EnumerateValueTest();
break; break;
#endif
#if 0
case '8':
test8();
break;
#endif
#if 0
case '9':
test9();
break;
#endif
} }
} }
return 0; return(0);
} }