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.

124 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. rtunload.c
  5. Abstract:
  6. NT level registry api test program, basic non-error paths.
  7. Perform an NtUnloadKey call to unlink a hive file from the registry.
  8. rtunload <KeyPath>
  9. Example:
  10. rtunload \registry\user\JVert
  11. Author:
  12. John Vert (jvert) 17-Apr-92
  13. Revision History:
  14. --*/
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #define WORK_SIZE 1024
  22. void __cdecl main(int, char *);
  23. void processargs();
  24. UNICODE_STRING KeyPath;
  25. WCHAR KeyPathBuffer[WORK_SIZE];
  26. void
  27. __cdecl main(
  28. int argc,
  29. char *argv[]
  30. )
  31. {
  32. NTSTATUS status;
  33. OBJECT_ATTRIBUTES KeyAttributes;
  34. IO_STATUS_BLOCK IoStatus;
  35. HANDLE FileHandle;
  36. HANDLE KeyHandle;
  37. BOOLEAN WasEnabled;
  38. //
  39. // Process args
  40. //
  41. KeyPath.MaximumLength = WORK_SIZE;
  42. KeyPath.Length = 0L;
  43. KeyPath.Buffer = &(KeyPathBuffer[0]);
  44. processargs(argc, argv);
  45. printf("rtunload: starting\n");
  46. RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, TRUE, FALSE, &WasEnabled);
  47. //
  48. // Set up KeyPath
  49. //
  50. InitializeObjectAttributes(
  51. &KeyAttributes,
  52. &KeyPath,
  53. OBJ_CASE_INSENSITIVE,
  54. (HANDLE)NULL,
  55. NULL
  56. );
  57. status = NtUnloadKey(&KeyAttributes);
  58. RtlAdjustPrivilege(SE_RESTORE_PRIVILEGE, WasEnabled, FALSE, &WasEnabled);
  59. if (!NT_SUCCESS(status)) {
  60. printf("rtunload: key unload failed status = %08lx\n", status);
  61. exit(1);
  62. } else {
  63. printf("rtunload: success!\n");
  64. }
  65. exit(0);
  66. }
  67. void
  68. processargs(
  69. int argc,
  70. char *argv[]
  71. )
  72. {
  73. ANSI_STRING temp;
  74. if ( (argc != 2) )
  75. {
  76. printf("Usage: %s <KeyName>\n",
  77. argv[0]);
  78. exit(1);
  79. }
  80. RtlInitAnsiString(
  81. &temp,
  82. argv[1]
  83. );
  84. RtlAnsiStringToUnicodeString(
  85. &KeyPath,
  86. &temp,
  87. TRUE
  88. );
  89. return;
  90. }