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.

143 lines
4.3 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 <windows.h>
  12. #include <tchar.h>
  13. #include <stdio.h>
  14. #include "setuplib.h"
  15. #include "resource.h"
  16. #define TERMINAL_SERVER_CLIENT_REGKEY _T("Software\\Microsoft\\Terminal Server Client")
  17. #define LOGFILE_STR _T("LogFile")
  18. HANDLE g_hLogFile = INVALID_HANDLE_VALUE;
  19. int __cdecl main(int argc, char** argv)
  20. {
  21. DWORD status;
  22. HKEY hKey;
  23. HINSTANCE hInstance = (HINSTANCE) NULL;
  24. TCHAR buffer[MAX_PATH];
  25. TCHAR szProgmanPath[MAX_PATH] = _T("");
  26. TCHAR szOldProgmanPath[MAX_PATH] = _T("");
  27. DWORD bufLen;
  28. TCHAR szMigratePathLaunch[MAX_PATH];
  29. //
  30. // Open the tsclient registry key to get the log file name
  31. //
  32. memset(buffer, 0, sizeof(buffer));
  33. bufLen = sizeof(buffer); //size in bytes needed
  34. status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  35. TERMINAL_SERVER_CLIENT_REGKEY,
  36. 0, KEY_READ, &hKey);
  37. if(ERROR_SUCCESS == status)
  38. {
  39. //
  40. // Query the tsclient optional logfile path
  41. //
  42. status = RegQueryValueEx(hKey, LOGFILE_STR,
  43. NULL, NULL, (BYTE *)buffer, &bufLen);
  44. if(ERROR_SUCCESS == status)
  45. {
  46. g_hLogFile = CreateFile(buffer,
  47. GENERIC_READ | GENERIC_WRITE,
  48. 0,
  49. NULL,
  50. OPEN_ALWAYS,
  51. FILE_ATTRIBUTE_NORMAL,
  52. NULL);
  53. if(g_hLogFile != INVALID_HANDLE_VALUE)
  54. {
  55. //Always append to the end of the log file
  56. SetFilePointer(g_hLogFile,
  57. 0,
  58. 0,
  59. FILE_END);
  60. }
  61. else
  62. {
  63. DBGMSG((_T("CreateFile for log file failed %d %d"),
  64. g_hLogFile, GetLastError()));
  65. }
  66. }
  67. else
  68. {
  69. DBGMSG((_T("RegQueryValueEx for log file failed %d %d"),
  70. status, GetLastError()));
  71. }
  72. RegCloseKey(hKey);
  73. }
  74. if(g_hLogFile != INVALID_HANDLE_VALUE)
  75. {
  76. DBGMSG((_T("Log file opened by new process attach")));
  77. }
  78. DeleteTSCDesktopShortcuts();
  79. LoadString(hInstance, IDS_PROGMAN_GROUP, szProgmanPath, sizeof(szProgmanPath) / sizeof(TCHAR));
  80. DeleteTSCFromStartMenu(szProgmanPath);
  81. LoadString(hInstance, IDS_OLD_NAME, szOldProgmanPath, sizeof(szOldProgmanPath) / sizeof(TCHAR));
  82. DeleteTSCFromStartMenu(szOldProgmanPath);
  83. DeleteTSCProgramFiles();
  84. DeleteTSCRegKeys();
  85. UninstallTSACMsi();
  86. //
  87. // Start registry and connection file migration
  88. //
  89. PROCESS_INFORMATION pinfo;
  90. STARTUPINFO sinfo;
  91. ZeroMemory(&sinfo, sizeof(sinfo));
  92. sinfo.cb = sizeof(sinfo);
  93. //
  94. // CreateProcess modifies buffer we pass it so it can't
  95. // be a static string
  96. //
  97. _tcscpy(szMigratePathLaunch, _T("mstsc.exe /migrate"));
  98. if (CreateProcess(NULL, // name of executable module
  99. szMigratePathLaunch, // command line string
  100. NULL, // SD
  101. NULL, // SD
  102. FALSE, // handle inheritance option
  103. CREATE_NEW_PROCESS_GROUP, // creation flags
  104. NULL, // new environment block
  105. NULL, // current directory name
  106. &sinfo, // startup information
  107. &pinfo // process information
  108. )) {
  109. DBGMSG((_T("Started mstsc.exe /migrate")));
  110. }
  111. else {
  112. DBGMSG((_T("Failed to starte mstsc.exe /migrate: %d"), GetLastError()));
  113. }
  114. }