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

rtreplac.c

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

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