Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

rtqval.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1991 Microsoft Corporation 00004 00005 Module Name: 00006 00007 rtqval.c 00008 00009 Abstract: 00010 00011 NT level registry api test program, basic non-error paths. 00012 00013 Do a query on a value. 00014 00015 rtqval <KeyPath> <valuename> [infotypenumber] [bufferlength] 00016 00017 Example: 00018 00019 rtqval \REGISTRY\MACHINE\TEST\bigkey value1 1 100 00020 00021 Author: 00022 00023 Bryan Willman (bryanwi) 9-Apr-92 00024 00025 Revision History: 00026 00027 --*/ 00028 00029 #include "cmp.h" 00030 #include <stdio.h> 00031 #include <stdlib.h> 00032 #include <string.h> 00033 00034 #define WORK_SIZE 1024 00035 00036 void __cdecl main(int, char *); 00037 void processargs(); 00038 00039 UNICODE_STRING WorkName; 00040 WCHAR workbuffer[WORK_SIZE]; 00041 00042 00043 00044 UNICODE_STRING WorkName2; 00045 WCHAR workbuffer2[WORK_SIZE]; 00046 00047 00048 UCHAR Buffer[1024*64]; 00049 00050 ULONG InfoType = KeyValueFullInformation; 00051 ULONG BufferSize = -1; 00052 00053 void 00054 __cdecl main( 00055 int argc, 00056 char *argv[] 00057 ) 00058 { 00059 NTSTATUS status; 00060 OBJECT_ATTRIBUTES ObjectAttributes; 00061 HANDLE BaseHandle; 00062 ULONG Sizes[] = { sizeof(KEY_VALUE_BASIC_INFORMATION), 00063 sizeof(KEY_VALUE_FULL_INFORMATION) }; 00064 ULONG ResultLength; 00065 PKEY_VALUE_BASIC_INFORMATION pbasic; 00066 PKEY_VALUE_FULL_INFORMATION pfull; 00067 PKEY_VALUE_PARTIAL_INFORMATION ppartial; 00068 00069 // 00070 // Process args 00071 // 00072 00073 WorkName.MaximumLength = WORK_SIZE; 00074 WorkName.Length = 0L; 00075 WorkName.Buffer = &(workbuffer[0]); 00076 00077 WorkName2.MaximumLength = WORK_SIZE; 00078 WorkName2.Length = 0L; 00079 WorkName2.Buffer = &(workbuffer2[0]); 00080 00081 processargs(argc, argv); 00082 00083 00084 // 00085 // Set up and open KeyPath 00086 // 00087 00088 printf("rtqkey: starting\n"); 00089 00090 InitializeObjectAttributes( 00091 &ObjectAttributes, 00092 &WorkName, 00093 0, 00094 (HANDLE)NULL, 00095 NULL 00096 ); 00097 ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; 00098 00099 status = NtOpenKey( 00100 &BaseHandle, 00101 KEY_QUERY_VALUE, 00102 &ObjectAttributes 00103 ); 00104 if (!NT_SUCCESS(status)) { 00105 printf("rtqkey: t0: %08lx\n", status); 00106 exit(1); 00107 } 00108 00109 // 00110 // make test call 00111 // 00112 RtlFillMemory((PVOID)&(Buffer[0]), 1024*64, 0xaa); 00113 00114 if (BufferSize == -1) { 00115 BufferSize = Sizes[InfoType]; 00116 } 00117 00118 status = NtQueryValueKey( 00119 BaseHandle, 00120 &WorkName2, 00121 InfoType, 00122 (PVOID)&(Buffer[0]), 00123 BufferSize, 00124 &ResultLength 00125 ); 00126 00127 printf("status = %08lx ResultLength = %08lx\n", status, ResultLength); 00128 switch (InfoType) { 00129 case KeyValueBasicInformation: 00130 pbasic = (PKEY_VALUE_BASIC_INFORMATION)Buffer; 00131 printf("TitleIndex: %08lx\n", pbasic->TitleIndex); 00132 printf(" Type: %08lx\n", pbasic->Type); 00133 printf("NameLength: %08lx\n", pbasic->NameLength); 00134 printf(" Name: '%.*ws'\n", pbasic->NameLength/2, &(pbasic->Name)); 00135 break; 00136 00137 case KeyValueFullInformation: 00138 pfull = (PKEY_VALUE_FULL_INFORMATION)Buffer; 00139 printf("TitleIndex: %08lx\n", pfull->TitleIndex); 00140 printf(" Type: %08lx\n", pfull->Type); 00141 printf("DataOffset: %08lx\n", pfull->DataOffset); 00142 printf("DataLength: %08lx\n", pfull->DataLength); 00143 printf("NameLength: %08lx\n", pfull->NameLength); 00144 printf(" Name: '%.*ws'\n", pfull->NameLength/2, &(pfull->Name)); 00145 printf(" Data: '%.*ws'\n", pfull->DataLength/2, 00146 ((PUCHAR)pfull + pfull->DataOffset) ); 00147 break; 00148 00149 case KeyValuePartialInformation: 00150 ppartial = (PKEY_VALUE_PARTIAL_INFORMATION)Buffer; 00151 printf("TitleIndex: %08lx\n", ppartial->TitleIndex); 00152 printf(" Type: %08lx\n", ppartial->Type); 00153 printf("DataLength: %08lx\n", ppartial->DataLength); 00154 printf(" Data: '%.*ws'\n", ppartial->DataLength/2, 00155 ((PUCHAR)&(ppartial->Data))); 00156 break; 00157 } 00158 00159 NtClose(BaseHandle); 00160 exit(0); 00161 } 00162 00163 void 00164 processargs( 00165 int argc, 00166 char *argv[] 00167 ) 00168 { 00169 ANSI_STRING temp; 00170 00171 if ( (argc < 2) ) 00172 { 00173 printf("Usage: %s <KeyPath> [infotype] [bufferlen]\n", 00174 argv[0]); 00175 exit(1); 00176 } 00177 00178 RtlInitAnsiString( 00179 &temp, 00180 argv[1] 00181 ); 00182 00183 RtlAnsiStringToUnicodeString( 00184 &WorkName, 00185 &temp, 00186 TRUE 00187 ); 00188 00189 RtlInitAnsiString( 00190 &temp, 00191 argv[2] 00192 ); 00193 00194 RtlAnsiStringToUnicodeString( 00195 &WorkName2, 00196 &temp, 00197 TRUE 00198 ); 00199 00200 if (argc > 3) { 00201 InfoType = atoi(argv[3]); 00202 } 00203 00204 if (argc > 4) { 00205 BufferSize = atoi(argv[4]); 00206 } 00207 00208 return; 00209 }

Generated on Sat May 15 19:41:41 2004 for test by doxygen 1.3.7