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

rtrest2.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1991 Microsoft Corporation 00004 00005 Module Name: 00006 00007 rtrest2.c 00008 00009 Abstract: 00010 00011 NT level registry api test program, basic error path 00012 00013 Creates a key "Key1" and a subkey, "Key2" 00014 00015 Calls NtSaveKey on Key1, then NtRestoreKey while a handle to Key2 is 00016 still open. 00017 00018 rtrest2 <KeyPath> <FileName> 00019 00020 Example: 00021 00022 rtrest2 \registry\machine\system\test tempfile 00023 00024 Author: 00025 00026 John Vert (jvert) 13-Jun-1992 00027 00028 Revision History: 00029 00030 --*/ 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 FileName; 00046 WCHAR FileNameBuffer[WORK_SIZE]; 00047 00048 void 00049 __cdecl main( 00050 int argc, 00051 char *argv[] 00052 ) 00053 { 00054 NTSTATUS status; 00055 OBJECT_ATTRIBUTES ObjectAttributes; 00056 IO_STATUS_BLOCK IoStatus; 00057 HANDLE FileHandle; 00058 HANDLE KeyHandle; 00059 00060 // 00061 // Process args 00062 // 00063 00064 KeyPath.MaximumLength = WORK_SIZE; 00065 KeyPath.Length = 0L; 00066 KeyPath.Buffer = &(KeyPathBuffer[0]); 00067 00068 FileName.MaximumLength = WORK_SIZE; 00069 FileName.Length = 0L; 00070 FileName.Buffer = &(FileNameBuffer[0]); 00071 00072 processargs(argc, argv); 00073 00074 00075 // 00076 // Set up and open FileName 00077 // 00078 00079 printf("rtrestor: starting\n"); 00080 00081 InitializeObjectAttributes( 00082 &ObjectAttributes, 00083 &FileName, 00084 0, 00085 (HANDLE)NULL, 00086 NULL 00087 ); 00088 ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; 00089 00090 status = NtCreateFile( 00091 &FileHandle, 00092 GENERIC_READ | SYNCHRONIZE, 00093 &ObjectAttributes, 00094 &IoStatus, 00095 0, // AllocationSize 00096 FILE_ATTRIBUTE_NORMAL, 00097 0, // ShareAccess 00098 FILE_OPEN_IF, 00099 FILE_SYNCHRONOUS_IO_NONALERT, 00100 NULL, // EaBuffer 00101 0 // EaLength 00102 ); 00103 00104 if (!NT_SUCCESS(status)) { 00105 printf("rtsave: file open failed status = %08lx\n", status); 00106 exit(1); 00107 } 00108 00109 InitializeObjectAttributes( 00110 &ObjectAttributes, 00111 &KeyPath, 00112 0, 00113 (HANDLE)NULL, 00114 NULL 00115 ); 00116 ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; 00117 00118 status = NtOpenKey( 00119 &KeyHandle, 00120 MAXIMUM_ALLOWED, 00121 &ObjectAttributes 00122 ); 00123 if (!NT_SUCCESS(status)) { 00124 printf("rtsave: key open failed status = %08lx\n", status); 00125 exit(1); 00126 } 00127 00128 status = NtRestoreKey(KeyHandle, FileHandle); 00129 00130 if (!NT_SUCCESS(status)) { 00131 printf("rtrestor: NtRestorKey failed status = %08lx\n", status); 00132 exit(1); 00133 } 00134 00135 printf("rtsave: success\n"); 00136 exit(0); 00137 } 00138 00139 void 00140 processargs( 00141 int argc, 00142 char *argv[] 00143 ) 00144 { 00145 ANSI_STRING temp; 00146 00147 if ( (argc != 3) ) 00148 { 00149 printf("Usage: %s <KeyName> <FileName>\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 &FileName, 00172 &temp, 00173 TRUE 00174 ); 00175 00176 return; 00177 }

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