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.

129 lines
2.5 KiB

  1. //
  2. // RDCERT.CPP
  3. // Created 4/19/2000 MadanA
  4. //
  5. // Sample program that install the remote desktop certificate.
  6. // - no argment installs the certificate
  7. // - /C clears the remote desktop certificate from store.
  8. // - /? display this message.
  9. //
  10. #include "precomp.h"
  11. //
  12. // Main entry point
  13. //
  14. void
  15. __cdecl
  16. main(
  17. int argc,
  18. char **argv
  19. )
  20. {
  21. BOOL bCleanup = FALSE;
  22. DWORD dwError = ERROR_SUCCESS;
  23. CHAR achUserName[UNLEN + 1];
  24. CHAR achComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  25. LPSTR szUserName = NULL;
  26. LPSTR szDomainName = NULL;
  27. LPSTR szComputerName = NULL;
  28. DWORD dwNameLen;
  29. //
  30. // parse command line parameters.
  31. //
  32. if ( argc > 1 ) {
  33. if( argc > 2 ) {
  34. //
  35. // we expect only one paramter.
  36. //
  37. goto Usage;
  38. }
  39. if( argv[1][0] != '/') {
  40. //
  41. // option should start with /
  42. //
  43. goto Usage;
  44. }
  45. switch ( argv[1][1] ) {
  46. case 'c':
  47. case 'C':
  48. bCleanup = TRUE;
  49. break;
  50. case '?':
  51. default:
  52. goto Usage;
  53. }
  54. }
  55. if( bCleanup ) {
  56. NmMakeCertCleanup( NULL, NULL, NULL, 0);
  57. goto Cleanup;
  58. }
  59. dwNameLen = sizeof(achUserName);
  60. if( GetUserNameA((LPSTR)achUserName, &dwNameLen) ) {
  61. szUserName = (LPSTR)achUserName;
  62. }
  63. else {
  64. printf("GetUserNameA failed, %d.\n", GetLastError());
  65. }
  66. dwNameLen = sizeof(achComputerName);
  67. if( GetComputerNameA((LPSTR)achComputerName, &dwNameLen) ) {
  68. szComputerName = (LPSTR)achComputerName;
  69. }
  70. else {
  71. printf("GetComputerNameA failed, %d.\n", GetLastError());
  72. }
  73. dwError =
  74. NmMakeCert(
  75. szUserName,
  76. szDomainName,
  77. szComputerName,
  78. NULL,
  79. NULL,
  80. 0 );
  81. if( dwError != 1 ) {
  82. printf("NmMakeCert failed, %d.\n", dwError);
  83. goto Cleanup;
  84. }
  85. dwError = ERROR_SUCCESS;
  86. goto Cleanup;
  87. Usage:
  88. printf("\n");
  89. printf("rdcert [/c]\n");
  90. printf("\n");
  91. printf("Install/Uninstall Remote Desktop Certificate.\n");
  92. printf("\t noargument - Install Remote Desktop Certificate.\n");
  93. printf("\t /c - Uninstall already installed Remote Desktop Certificate.\n");
  94. printf("\t /? - print this information.");
  95. printf("\n");
  96. Cleanup:
  97. if( dwError == ERROR_SUCCESS ) {
  98. printf("The command completed successfully.\n");
  99. }
  100. return;
  101. }