Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. rtload.c
  5. Abstract:
  6. NT level registry api test program, basic non-error paths.
  7. Perform an NtLoadKey call to link a hive file into the registry.
  8. If KeyPath is not present, it loads the hive file at
  9. \Registry\User\FileName
  10. rtload [ <KeyPath> ] <FileName>
  11. Example:
  12. rtload \registry\user\JVert JVUser
  13. Author:
  14. John Vert (jvert) 15-Apr-92
  15. Revision History:
  16. --*/
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #define WORK_SIZE 1024
  24. void __cdecl main(int, char *);
  25. void processargs();
  26. UNICODE_STRING KeyPath;
  27. WCHAR KeyPathBuffer[WORK_SIZE];
  28. UNICODE_STRING FileName;
  29. WCHAR FileNameBuffer[WORK_SIZE];
  30. OBJECT_ATTRIBUTES FileAttributes;
  31. OBJECT_ATTRIBUTES KeyAttributes;
  32. RTL_RELATIVE_NAME RelativeName;
  33. void
  34. __cdecl main(
  35. int argc,
  36. char *argv[]
  37. )
  38. {
  39. NTSTATUS status;
  40. IO_STATUS_BLOCK IoStatus;
  41. HANDLE FileHandle;
  42. HANDLE KeyHandle;
  43. //
  44. // Process args
  45. //
  46. KeyPath.MaximumLength = WORK_SIZE;
  47. KeyPath.Length = 0L;
  48. KeyPath.Buffer = &(KeyPathBuffer[0]);
  49. FileName.MaximumLength = WORK_SIZE;
  50. FileName.Length = 0L;
  51. FileName.Buffer = &(FileNameBuffer[0]);
  52. processargs(argc, argv);
  53. //
  54. // Set up FileName
  55. //
  56. printf("rtload: starting\n");
  57. status = NtLoadKey(&KeyAttributes, &FileAttributes);
  58. if (!NT_SUCCESS(status)) {
  59. printf("rtload: key load failed status = %08lx\n", status);
  60. exit(1);
  61. } else {
  62. printf("rtload: success!\n");
  63. }
  64. exit(0);
  65. }
  66. void
  67. processargs(
  68. int argc,
  69. char *argv[]
  70. )
  71. {
  72. ANSI_STRING temp;
  73. UNICODE_STRING DosFileName;
  74. HANDLE UserHandle;
  75. PWSTR FilePart;
  76. NTSTATUS Status;
  77. if ( (argc != 2) && (argc != 3))
  78. {
  79. printf("Usage: %s [ <KeyName> ] <FileName>\n",
  80. argv[0]);
  81. exit(1);
  82. }
  83. if (argc == 3) {
  84. RtlInitAnsiString(
  85. &temp,
  86. argv[1]
  87. );
  88. RtlAnsiStringToUnicodeString(
  89. &KeyPath,
  90. &temp,
  91. TRUE
  92. );
  93. RtlInitAnsiString(
  94. &temp,
  95. argv[2]
  96. );
  97. RtlAnsiStringToUnicodeString(
  98. &DosFileName,
  99. &temp,
  100. TRUE
  101. );
  102. RtlDosPathNameToNtPathName_U( DosFileName.Buffer,
  103. &FileName,
  104. NULL,
  105. NULL );
  106. InitializeObjectAttributes(
  107. &FileAttributes,
  108. &FileName,
  109. OBJ_CASE_INSENSITIVE,
  110. (HANDLE)NULL,
  111. NULL
  112. );
  113. //
  114. // Set up KeyPath
  115. //
  116. InitializeObjectAttributes(
  117. &KeyAttributes,
  118. &KeyPath,
  119. OBJ_CASE_INSENSITIVE,
  120. (HANDLE)NULL,
  121. NULL
  122. );
  123. } else if (argc==2) {
  124. RtlInitAnsiString(&temp, argv[1]);
  125. RtlAnsiStringToUnicodeString(&DosFileName, &temp, TRUE);
  126. RtlDosPathNameToNtPathName_U( DosFileName.Buffer,
  127. &FileName,
  128. &FilePart,
  129. &RelativeName );
  130. InitializeObjectAttributes( &FileAttributes,
  131. &RelativeName.RelativeName,
  132. OBJ_CASE_INSENSITIVE,
  133. RelativeName.ContainingDirectory,
  134. NULL );
  135. RtlInitUnicodeString(&KeyPath, L"\\Registry\\User");
  136. InitializeObjectAttributes( &KeyAttributes,
  137. &KeyPath,
  138. OBJ_CASE_INSENSITIVE,
  139. NULL,
  140. NULL );
  141. Status = NtOpenKey( &UserHandle,
  142. KEY_READ,
  143. &KeyAttributes);
  144. if (!NT_SUCCESS(Status)) {
  145. printf("Couldn't open \\Registry\\User, status %08lx\n",Status);
  146. exit(1);
  147. }
  148. RtlInitUnicodeString(&KeyPath, FilePart);
  149. InitializeObjectAttributes( &KeyAttributes,
  150. &KeyPath,
  151. OBJ_CASE_INSENSITIVE,
  152. UserHandle,
  153. NULL );
  154. }
  155. return;
  156. }