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.

182 lines
3.5 KiB

  1. // stdafx.cpp : source file that includes just the standard includes
  2. // stdafx.pch will be the pre-compiled header
  3. // stdafx.obj will contain the pre-compiled type information
  4. #include "stdafx.h"
  5. #ifdef _ATL_STATIC_REGISTRY
  6. #include <statreg.h>
  7. #include <statreg.cpp>
  8. #endif
  9. #include <atlimpl.cpp>
  10. #define COUNT_OF(a) (sizeof(a) / sizeof(a[0]))
  11. //---------------------------------------------------------------------------
  12. // CAdmtModule Class
  13. //---------------------------------------------------------------------------
  14. CAdmtModule::CAdmtModule()
  15. {
  16. }
  17. CAdmtModule::~CAdmtModule()
  18. {
  19. }
  20. // OpenLog Method
  21. bool CAdmtModule::OpenLog()
  22. {
  23. // CloseLog(); // error class doesn't reset file pointer to NULL when closing file
  24. return m_Error.LogOpen(GetLogFolder() + _T("Migration.log"), 0, 0, true) ? true : false;
  25. }
  26. // CloseLog Method
  27. void CAdmtModule::CloseLog()
  28. {
  29. m_Error.LogClose();
  30. }
  31. // Log Method
  32. void __cdecl CAdmtModule::Log(UINT uLevel, UINT uId, ...)
  33. {
  34. _TCHAR szFormat[512];
  35. _TCHAR szMessage[1024];
  36. if (LoadString(GetResourceInstance(), uId, szFormat, 512))
  37. {
  38. va_list args;
  39. va_start(args, uId);
  40. _vsntprintf(szMessage, COUNT_OF(szMessage), szFormat, args);
  41. va_end(args);
  42. szMessage[1023] = _T('\0');
  43. }
  44. else
  45. {
  46. szMessage[0] = _T('\0');
  47. }
  48. m_Error.MsgProcess(uLevel | uId, szMessage);
  49. }
  50. // Log Method
  51. void __cdecl CAdmtModule::Log(LPCTSTR pszFormat, ...)
  52. {
  53. _TCHAR szMessage[1024];
  54. if (pszFormat)
  55. {
  56. va_list args;
  57. va_start(args, pszFormat);
  58. _vsntprintf(szMessage, COUNT_OF(szMessage), pszFormat, args);
  59. va_end(args);
  60. szMessage[1023] = _T('\0');
  61. }
  62. else
  63. {
  64. szMessage[0] = _T('\0');
  65. }
  66. m_Error.MsgProcess(0, szMessage);
  67. }
  68. StringLoader gString;
  69. //#import <ActiveDs.tlb> no_namespace implementation_only exclude("_LARGE_INTEGER","_SYSTEMTIME")
  70. #import <DBMgr.tlb> no_namespace implementation_only
  71. #import <MigDrvr.tlb> no_namespace implementation_only
  72. #import <VarSet.tlb> no_namespace rename("property", "aproperty") implementation_only
  73. #import <WorkObj.tlb> no_namespace implementation_only
  74. #import <MsPwdMig.tlb> no_namespace implementation_only
  75. #import "Internal.tlb" no_namespace implementation_only
  76. // GetLogFolder Method
  77. _bstr_t GetLogFolder()
  78. {
  79. _bstr_t strFolder;
  80. HKEY hKey;
  81. DWORD dwError = RegOpenKey(HKEY_LOCAL_MACHINE, _T("Software\\Mission Critical Software\\DomainAdmin"), &hKey);
  82. if (dwError == ERROR_SUCCESS)
  83. {
  84. _TCHAR szPath[_MAX_PATH];
  85. DWORD cbPath = sizeof(szPath);
  86. dwError = RegQueryValueEx(hKey, _T("Directory"), NULL, NULL, (LPBYTE)szPath, &cbPath);
  87. if (dwError == ERROR_SUCCESS)
  88. {
  89. _TCHAR szDrive[_MAX_DRIVE];
  90. _TCHAR szDir[_MAX_DIR];
  91. _tsplitpath(szPath, szDrive, szDir, NULL, NULL);
  92. _tcscat(szDir, _T("Logs"));
  93. _tmakepath(szPath, szDrive, szDir, NULL, NULL);
  94. strFolder = szPath;
  95. }
  96. RegCloseKey(hKey);
  97. }
  98. return strFolder;
  99. }
  100. // GetReportsFolder Method
  101. _bstr_t GetReportsFolder()
  102. {
  103. _bstr_t strFolder;
  104. HKEY hKey;
  105. DWORD dwError = RegOpenKey(HKEY_LOCAL_MACHINE, _T("Software\\Mission Critical Software\\DomainAdmin"), &hKey);
  106. if (dwError == ERROR_SUCCESS)
  107. {
  108. _TCHAR szPath[_MAX_PATH];
  109. DWORD cbPath = sizeof(szPath);
  110. dwError = RegQueryValueEx(hKey, _T("Directory"), NULL, NULL, (LPBYTE)szPath, &cbPath);
  111. if (dwError == ERROR_SUCCESS)
  112. {
  113. _TCHAR szDrive[_MAX_DRIVE];
  114. _TCHAR szDir[_MAX_DIR];
  115. _tsplitpath(szPath, szDrive, szDir, NULL, NULL);
  116. _tcscat(szDir, _T("Reports"));
  117. _tmakepath(szPath, szDrive, szDir, NULL, NULL);
  118. CreateDirectory(szPath, NULL);
  119. strFolder = szPath;
  120. }
  121. RegCloseKey(hKey);
  122. }
  123. return strFolder;
  124. }