Leaked source code of windows server 2003
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.

149 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. rtdelval.c
  5. Abstract:
  6. NT level registry api test program, basic non-error paths.
  7. Delete a key's value entry (field)
  8. rtdelval <KeyPath> <value entry name>
  9. Example:
  10. rtdelval \REGISTRY\MACHINE\TEST\bigkey first_value_field
  11. Author:
  12. Bryan Willman (bryanwi) 10-Jan-92
  13. Revision History:
  14. --*/
  15. #include "cmp.h"
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #define WORK_SIZE 1024
  20. void __cdecl main(int, char *);
  21. void processargs();
  22. void
  23. Delete(
  24. HANDLE Handle
  25. );
  26. UNICODE_STRING WorkName;
  27. WCHAR workbuffer[WORK_SIZE];
  28. UNICODE_STRING ValueName;
  29. WCHAR valuebuffer[WORK_SIZE];
  30. void
  31. __cdecl main(
  32. int argc,
  33. char *argv[]
  34. )
  35. {
  36. NTSTATUS status;
  37. OBJECT_ATTRIBUTES ObjectAttributes;
  38. HANDLE BaseHandle;
  39. //
  40. // Process args
  41. //
  42. WorkName.MaximumLength = WORK_SIZE;
  43. WorkName.Length = 0L;
  44. WorkName.Buffer = &(workbuffer[0]);
  45. ValueName.MaximumLength = WORK_SIZE;
  46. ValueName.Length = 0L;
  47. ValueName.Buffer = &(valuebuffer[0]);
  48. processargs(argc, argv);
  49. //
  50. // Set up and open KeyPath
  51. //
  52. printf("rtdelval: starting\n");
  53. InitializeObjectAttributes(
  54. &ObjectAttributes,
  55. &WorkName,
  56. 0,
  57. (HANDLE)NULL,
  58. NULL
  59. );
  60. ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
  61. status = NtOpenKey(
  62. &BaseHandle,
  63. KEY_SET_VALUE,
  64. &ObjectAttributes
  65. );
  66. if (!NT_SUCCESS(status)) {
  67. printf("rtdelval: t0: %08lx\n", status);
  68. exit(1);
  69. }
  70. status = NtDeleteValueKey(BaseHandle, &ValueName);
  71. if (!NT_SUCCESS(status)) {
  72. printf("rtdelval: t1: %08lx\n", status);
  73. exit(1);
  74. }
  75. NtClose(BaseHandle);
  76. exit(0);
  77. }
  78. void
  79. processargs(
  80. int argc,
  81. char *argv[]
  82. )
  83. {
  84. ANSI_STRING temp;
  85. if ( (argc != 3) )
  86. {
  87. printf("Usage: %s <KeyPath> <value entry name>\n",
  88. argv[0]);
  89. exit(1);
  90. }
  91. RtlInitAnsiString(
  92. &temp,
  93. argv[1]
  94. );
  95. RtlAnsiStringToUnicodeString(
  96. &WorkName,
  97. &temp,
  98. TRUE
  99. );
  100. RtlInitAnsiString(
  101. &temp,
  102. argv[2]
  103. );
  104. RtlAnsiStringToUnicodeString(
  105. &ValueName,
  106. &temp,
  107. TRUE
  108. );
  109. return;
  110. }