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.

163 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. tdelete.c
  5. Abstract:
  6. Test for cluster object creation APIs
  7. Author:
  8. John Vert (jvert) 3-May-1996
  9. Revision History:
  10. --*/
  11. #include "windows.h"
  12. #include "cluster.h"
  13. #include "stdio.h"
  14. #include "stdlib.h"
  15. LPWSTR ClusterName=NULL;
  16. BOOL DoGroup=FALSE;
  17. BOOL DoResource=FALSE;
  18. LPWSTR Name=NULL;
  19. CHAR UsageText[] =
  20. "TDELETE [-c cluster] type name\n"
  21. " cluster\tspecifies the name of the cluster to connect to\n"
  22. " type\t\teither \"group\" or \"resource\"\n"
  23. " name\t\tthe friendly name of the object\n";
  24. void
  25. Usage(
  26. void
  27. )
  28. {
  29. fprintf(stderr, UsageText);
  30. exit(1);
  31. }
  32. LPWSTR
  33. GetString(
  34. IN LPSTR String
  35. )
  36. {
  37. LPWSTR wString;
  38. DWORD Length;
  39. Length = strlen(String)+1;
  40. wString = malloc(Length*sizeof(WCHAR));
  41. mbstowcs(wString, String, Length);
  42. return(wString);
  43. }
  44. void
  45. ParseArgs(
  46. int argc,
  47. char *argv[]
  48. )
  49. {
  50. int i;
  51. DWORD ArgsSeen=0;
  52. for (i=1;i<argc;i++) {
  53. if ((argv[i][0] == '-') ||
  54. (argv[i][0] == '/')) {
  55. switch (argv[i][1]) {
  56. case 'c':
  57. if (++i == argc) {
  58. Usage();
  59. }
  60. default:
  61. Usage();
  62. break;
  63. }
  64. } else {
  65. switch (ArgsSeen) {
  66. case 0:
  67. //
  68. // type
  69. //
  70. if (_stricmp(argv[i], "group")==0) {
  71. DoGroup = TRUE;
  72. } else if (_stricmp(argv[i], "resource") == 0) {
  73. DoResource = TRUE;
  74. } else {
  75. Usage();
  76. }
  77. ArgsSeen++;
  78. break;
  79. case 1:
  80. Name = GetString(argv[i]);
  81. ArgsSeen++;
  82. break;
  83. default:
  84. Usage();
  85. }
  86. }
  87. }
  88. }
  89. _cdecl
  90. main (argc, argv)
  91. int argc;
  92. char *argv[];
  93. {
  94. HCLUSTER hClus;
  95. HGROUP hGroup;
  96. HRESOURCE hResource;
  97. DWORD status;
  98. ParseArgs(argc, argv);
  99. hClus = OpenCluster(ClusterName);
  100. if (hClus == NULL) {
  101. fprintf(stderr,
  102. "OpenCluster %ws failed %d\n",
  103. (ClusterName == NULL) ? L"(NULL)" : ClusterName,
  104. GetLastError());
  105. return(0);
  106. }
  107. if (DoGroup) {
  108. hGroup = OpenClusterGroup(hClus, Name);
  109. if (hGroup == NULL) {
  110. fprintf(stderr,
  111. "OpenGroup %ws failed %d\n", Name, GetLastError());
  112. return(0);
  113. }
  114. status = DeleteClusterGroup( hGroup );
  115. if ( status != ERROR_SUCCESS ) {
  116. fprintf(stderr,
  117. "DeleteGroup %ws failed %d\n", Name, GetLastError());
  118. }
  119. CloseClusterGroup( hGroup );
  120. } else if (DoResource) {
  121. hResource = OpenClusterResource(hClus,
  122. Name);
  123. if (hResource == NULL) {
  124. fprintf(stderr,
  125. "OpenResource %ws failed %d\n", Name, GetLastError());
  126. return(0);
  127. }
  128. status = DeleteClusterResource( hResource );
  129. if ( status != ERROR_SUCCESS ) {
  130. fprintf(stderr,
  131. "DeleteResource %ws failed %d\n", Name, GetLastError());
  132. }
  133. CloseClusterResource( hResource );
  134. } else {
  135. Usage();
  136. }
  137. return(0);
  138. }