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.

96 lines
2.0 KiB

  1. //
  2. // Install.cpp
  3. //
  4. // Performs the actual installation work for the Home Networking Wizard.
  5. //
  6. #include "stdafx.h"
  7. #include "Install.h"
  8. #include "NetUtil.h"
  9. CLogFile g_logFile;
  10. void Install_SetWorkgroupName(LPCTSTR pszWorkgroup, BOOL* pfRebootRequired)
  11. {
  12. g_logFile.Write("Attempting to set workgroup name\r\n");
  13. TCHAR szOldWorkgroup[LM20_DNLEN + 1];
  14. GetWorkgroupName(szOldWorkgroup, _countof(szOldWorkgroup));
  15. if (0 != StrCmpI(szOldWorkgroup, pszWorkgroup))
  16. {
  17. if (SetWorkgroupName(pszWorkgroup))
  18. {
  19. g_logFile.Write("Workgroup name set: ");
  20. g_logFile.Write(pszWorkgroup);
  21. g_logFile.Write("\r\n");
  22. }
  23. else
  24. {
  25. g_logFile.Write("Set workgroup name failed.\r\n");
  26. }
  27. *pfRebootRequired = TRUE;
  28. }
  29. else
  30. {
  31. g_logFile.Write("Workgroup name is the same as the old one - not setting.\r\n");
  32. }
  33. }
  34. HRESULT CLogFile::Initialize(LPCSTR pszPath)
  35. {
  36. HRESULT hr = E_FAIL;
  37. CHAR szPathExpand[MAX_PATH];
  38. if (ExpandEnvironmentStringsA(pszPath, szPathExpand, ARRAYSIZE(szPathExpand)))
  39. {
  40. _hLogFile = CreateFileA(szPathExpand, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  41. if (INVALID_HANDLE_VALUE != _hLogFile)
  42. {
  43. hr = S_OK;
  44. Write(LOGNAMESTRA);
  45. }
  46. }
  47. return hr;
  48. }
  49. HRESULT CLogFile::Write(LPCSTR psz)
  50. {
  51. HRESULT hr = E_FAIL;
  52. if (_hLogFile)
  53. {
  54. DWORD cbWritten;
  55. BOOL fSuccess = WriteFile(_hLogFile, psz, lstrlenA(psz), &cbWritten, NULL);
  56. if (fSuccess)
  57. {
  58. hr = S_OK;
  59. }
  60. }
  61. return hr;
  62. }
  63. HRESULT CLogFile::Write(LPCWSTR psz)
  64. {
  65. CHAR szAnsi[512]; // Assume 512 is enough...
  66. if (SHUnicodeToAnsi(psz, szAnsi, ARRAYSIZE(szAnsi)))
  67. {
  68. return Write(szAnsi);
  69. }
  70. return E_FAIL;
  71. }
  72. HRESULT CLogFile::Uninitialize()
  73. {
  74. if (_hLogFile)
  75. {
  76. CloseHandle(_hLogFile);
  77. _hLogFile = NULL;
  78. }
  79. return S_OK;
  80. }