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.

175 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name :
  4. acme.cpp
  5. Abstract:
  6. remove acme installed client files and acme registry keys
  7. Author:
  8. JoyC
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #define ACME_REG_UNINSTALL_TS _T("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Terminal Server Client")
  13. #define UNINSTALL_REG_STR _T("UninstallString")
  14. //
  15. // List of TS client files installed
  16. //
  17. TCHAR* TSCFiles[] =
  18. {
  19. _T("cconman.cnt"),
  20. _T("cconman.hlp"),
  21. _T("conman.exe"),
  22. _T("mscreate.dir"),
  23. _T("mstsc.cnt"),
  24. _T("mstsc.exe"),
  25. _T("mstsc.hlp"),
  26. _T("rdpdr.dll")
  27. };
  28. //
  29. // Delete all the installed TS client files
  30. //
  31. void DeleteTSCProgramFiles()
  32. {
  33. DWORD status;
  34. HKEY hKey = NULL;
  35. HMODULE hShellModule = NULL;
  36. SHFILEOPSTRUCT FileOp;
  37. DWORD bufLen = MAX_PATH;
  38. TCHAR buffer[MAX_PATH] = _T("");
  39. TCHAR szOldInstallPath[MAX_PATH] = _T("");
  40. TCHAR szOldInstallPathRoot[MAX_PATH] = _T("");
  41. typedef DWORD (*PFnSHDeleteKey)(HKEY, LPCTSTR);
  42. PFnSHDeleteKey pfn = NULL;
  43. DBGMSG((_T("DeleteTSCProgramFiles")));
  44. //
  45. // Open the tsclient uninstall key
  46. //
  47. status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, ACME_REG_UNINSTALL_TS,
  48. 0, KEY_ALL_ACCESS, &hKey);
  49. if(ERROR_SUCCESS == status)
  50. {
  51. DBGMSG((_T("DeleteTSCProgramFiles: Opened ACME TSC uninstall registry key")));
  52. //
  53. // Query the uninstall value
  54. //
  55. if(ERROR_SUCCESS == RegQueryValueEx(hKey, UNINSTALL_REG_STR,
  56. NULL, NULL, (BYTE *)buffer, &bufLen))
  57. {
  58. TCHAR fname[_MAX_FNAME] = _T("");
  59. TCHAR drive[_MAX_DRIVE] = _T(""), dir[_MAX_DIR] = _T("");
  60. TCHAR ext[_MAX_EXT] = _T("");
  61. TCHAR FileFullPath[MAX_PATH];
  62. DWORD len;
  63. //
  64. // Get the uninstall directory
  65. //
  66. _tcscpy(szOldInstallPath, (TCHAR*)buffer);
  67. _tsplitpath(szOldInstallPath, drive, dir, fname, ext);
  68. _stprintf(szOldInstallPathRoot, _T("%s%s"), drive, dir);
  69. if(_tcslen(szOldInstallPathRoot) > 1 &&
  70. szOldInstallPathRoot[_tcslen(szOldInstallPathRoot) - 1] == _T('\\'))
  71. {
  72. szOldInstallPathRoot[_tcslen(szOldInstallPathRoot) - 1] = _T('\0');
  73. }
  74. DBGMSG((_T("DeleteTSCProgramFiles: uninstall directory: %s"),
  75. szOldInstallPathRoot));
  76. //
  77. // Delete the old setup folder
  78. //
  79. memset(&FileOp, 0, sizeof(FileOp));
  80. FileOp.wFunc = FO_DELETE;
  81. FileOp.pFrom = szOldInstallPathRoot;
  82. FileOp.pTo = NULL;
  83. FileOp.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
  84. SHFileOperation(&FileOp);
  85. //
  86. // Need to delete program files in the parent directory
  87. //
  88. _tcscpy(szOldInstallPath, szOldInstallPathRoot);
  89. _tsplitpath(szOldInstallPath, drive, dir, fname, ext);
  90. _stprintf(szOldInstallPathRoot, _T("%s%s"), drive, dir);
  91. if(szOldInstallPathRoot[_tcslen(szOldInstallPathRoot) - 1] == _T('\\'))
  92. {
  93. szOldInstallPathRoot[_tcslen(szOldInstallPathRoot) - 1] = _T('\0');
  94. }
  95. _tcscpy(FileFullPath, szOldInstallPathRoot);
  96. _tcscat(FileFullPath, _T("\\"));
  97. len = _tcslen(FileFullPath);
  98. DBGMSG((_T("DeleteTSCProgramFiles: TS client directory: %s"),
  99. FileFullPath));
  100. for (int i = 0; i < sizeof(TSCFiles) / sizeof(TSCFiles[0]); i++) {
  101. DWORD dwFileAttributes;
  102. FileFullPath[len] = _T('\0');
  103. _tcscat(FileFullPath, TSCFiles[i]);
  104. //
  105. // Remove the read only attribute for deleting
  106. //
  107. dwFileAttributes = GetFileAttributes(FileFullPath);
  108. dwFileAttributes &= ~(FILE_ATTRIBUTE_READONLY);
  109. SetFileAttributes(FileFullPath, dwFileAttributes);
  110. DeleteFile(FileFullPath);
  111. }
  112. //
  113. // Delete the directory if it's empty
  114. //
  115. FileFullPath[len] = _T('\0');
  116. RemoveDirectory(FileFullPath);
  117. }
  118. RegCloseKey(hKey);
  119. hShellModule = LoadLibrary (_T("shlwapi.dll"));
  120. if (hShellModule != NULL) {
  121. pfn = (PFnSHDeleteKey)GetProcAddress(hShellModule, "SHDeleteKey");
  122. if (pfn != NULL) {
  123. (*pfn)(HKEY_LOCAL_MACHINE, ACME_REG_UNINSTALL_TS);
  124. }
  125. else {
  126. RegDeleteKey(HKEY_LOCAL_MACHINE, ACME_REG_UNINSTALL_TS);
  127. }
  128. FreeLibrary (hShellModule);
  129. hShellModule = NULL;
  130. pfn = NULL;
  131. }
  132. else {
  133. RegDeleteKey(HKEY_LOCAL_MACHINE, ACME_REG_UNINSTALL_TS);
  134. }
  135. }
  136. else {
  137. DBGMSG((_T("DeleteTSCProgramFiles: Failed to open the ACME uninstall reg key: %d"),
  138. GetLastError()));
  139. }
  140. }