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

rtload.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1991 Microsoft Corporation 00004 00005 Module Name: 00006 00007 rtload.c 00008 00009 Abstract: 00010 00011 NT level registry api test program, basic non-error paths. 00012 00013 Perform an NtLoadKey call to link a hive file into the registry. 00014 00015 If KeyPath is not present, it loads the hive file at 00016 \Registry\User\FileName 00017 00018 rtload [ <KeyPath> ] <FileName> 00019 00020 Example: 00021 00022 rtload \registry\user\JVert JVUser 00023 00024 Author: 00025 00026 John Vert (jvert) 15-Apr-92 00027 00028 Revision History: 00029 00030 --*/ 00031 #include <nt.h> 00032 #include <ntrtl.h> 00033 #include <nturtl.h> 00034 00035 #include <stdio.h> 00036 #include <stdlib.h> 00037 #include <string.h> 00038 00039 #define WORK_SIZE 1024 00040 00041 void __cdecl main(int, char *); 00042 void processargs(); 00043 00044 UNICODE_STRING KeyPath; 00045 WCHAR KeyPathBuffer[WORK_SIZE]; 00046 00047 UNICODE_STRING FileName; 00048 WCHAR FileNameBuffer[WORK_SIZE]; 00049 00050 OBJECT_ATTRIBUTES FileAttributes; 00051 OBJECT_ATTRIBUTES KeyAttributes; 00052 RTL_RELATIVE_NAME RelativeName; 00053 00054 void 00055 __cdecl main( 00056 int argc, 00057 char *argv[] 00058 ) 00059 { 00060 NTSTATUS status; 00061 IO_STATUS_BLOCK IoStatus; 00062 HANDLE FileHandle; 00063 HANDLE KeyHandle; 00064 00065 // 00066 // Process args 00067 // 00068 00069 KeyPath.MaximumLength = WORK_SIZE; 00070 KeyPath.Length = 0L; 00071 KeyPath.Buffer = &(KeyPathBuffer[0]); 00072 00073 FileName.MaximumLength = WORK_SIZE; 00074 FileName.Length = 0L; 00075 FileName.Buffer = &(FileNameBuffer[0]); 00076 00077 processargs(argc, argv); 00078 00079 00080 // 00081 // Set up FileName 00082 // 00083 00084 printf("rtload: starting\n"); 00085 00086 00087 status = NtLoadKey(&KeyAttributes, &FileAttributes); 00088 if (!NT_SUCCESS(status)) { 00089 printf("rtload: key load failed status = %08lx\n", status); 00090 exit(1); 00091 } else { 00092 printf("rtload: success!\n"); 00093 } 00094 00095 exit(0); 00096 } 00097 00098 void 00099 processargs( 00100 int argc, 00101 char *argv[] 00102 ) 00103 { 00104 ANSI_STRING temp; 00105 UNICODE_STRING DosFileName; 00106 HANDLE UserHandle; 00107 PWSTR FilePart; 00108 NTSTATUS Status; 00109 00110 if ( (argc != 2) && (argc != 3)) 00111 { 00112 printf("Usage: %s [ <KeyName> ] <FileName>\n", 00113 argv[0]); 00114 exit(1); 00115 } 00116 if (argc == 3) { 00117 00118 RtlInitAnsiString( 00119 &temp, 00120 argv[1] 00121 ); 00122 00123 RtlAnsiStringToUnicodeString( 00124 &KeyPath, 00125 &temp, 00126 TRUE 00127 ); 00128 00129 RtlInitAnsiString( 00130 &temp, 00131 argv[2] 00132 ); 00133 00134 RtlAnsiStringToUnicodeString( 00135 &DosFileName, 00136 &temp, 00137 TRUE 00138 ); 00139 00140 RtlDosPathNameToNtPathName_U( DosFileName.Buffer, 00141 &FileName, 00142 NULL, 00143 NULL ); 00144 00145 InitializeObjectAttributes( 00146 &FileAttributes, 00147 &FileName, 00148 OBJ_CASE_INSENSITIVE, 00149 (HANDLE)NULL, 00150 NULL 00151 ); 00152 00153 // 00154 // Set up KeyPath 00155 // 00156 00157 InitializeObjectAttributes( 00158 &KeyAttributes, 00159 &KeyPath, 00160 OBJ_CASE_INSENSITIVE, 00161 (HANDLE)NULL, 00162 NULL 00163 ); 00164 } else if (argc==2) { 00165 RtlInitAnsiString(&temp, argv[1]); 00166 RtlAnsiStringToUnicodeString(&DosFileName, &temp, TRUE); 00167 RtlDosPathNameToNtPathName_U( DosFileName.Buffer, 00168 &FileName, 00169 &FilePart, 00170 &RelativeName ); 00171 00172 InitializeObjectAttributes( &FileAttributes, 00173 &RelativeName.RelativeName, 00174 OBJ_CASE_INSENSITIVE, 00175 RelativeName.ContainingDirectory, 00176 NULL ); 00177 00178 RtlInitUnicodeString(&KeyPath, L"\\Registry\\User"); 00179 InitializeObjectAttributes( &KeyAttributes, 00180 &KeyPath, 00181 OBJ_CASE_INSENSITIVE, 00182 NULL, 00183 NULL ); 00184 Status = NtOpenKey( &UserHandle, 00185 KEY_READ, 00186 &KeyAttributes); 00187 if (!NT_SUCCESS(Status)) { 00188 printf("Couldn't open \\Registry\\User, status %08lx\n",Status); 00189 exit(1); 00190 } 00191 00192 RtlInitUnicodeString(&KeyPath, FilePart); 00193 InitializeObjectAttributes( &KeyAttributes, 00194 &KeyPath, 00195 OBJ_CASE_INSENSITIVE, 00196 UserHandle, 00197 NULL ); 00198 00199 } 00200 00201 00202 return; 00203 }

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