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.

117 lines
2.3 KiB

  1. // Copyright (c) 2000 Microsoft Corporation
  2. //
  3. // Implementation of IConfigureYourServer::InstallService
  4. //
  5. // 31 Mar 2000 sburns
  6. // 05 Feb 2001 jeffjon Copied and modified for use with a Win32 version of CYS
  7. #include "pch.h"
  8. #include "resource.h"
  9. HRESULT
  10. CreateTempFile(const String& name, const String& contents)
  11. {
  12. LOG_FUNCTION2(createTempFile, name);
  13. ASSERT(!name.empty());
  14. ASSERT(!contents.empty());
  15. HRESULT hr = S_OK;
  16. HANDLE h = INVALID_HANDLE_VALUE;
  17. do
  18. {
  19. hr =
  20. FS::CreateFile(
  21. name,
  22. h,
  23. GENERIC_WRITE,
  24. 0,
  25. CREATE_ALWAYS,
  26. FILE_ATTRIBUTE_NORMAL);
  27. BREAK_ON_FAILED_HRESULT(hr);
  28. AnsiString ansi;
  29. contents.convert(ansi);
  30. ASSERT(!ansi.empty());
  31. // write to file with end of file character.
  32. hr = FS::Write(h, ansi + "\032");
  33. BREAK_ON_FAILED_HRESULT(hr);
  34. }
  35. while (0);
  36. Win::CloseHandle(h);
  37. return hr;
  38. }
  39. bool
  40. InstallServiceWithOcManager(
  41. const String& infText,
  42. const String& unattendText)
  43. {
  44. LOG_FUNCTION(SpawnInstaller);
  45. ASSERT(!unattendText.empty());
  46. // infText may be empty
  47. bool result = false;
  48. HRESULT hr = S_OK;
  49. String sysFolder = Win::GetSystemDirectory();
  50. String infPath = sysFolder + L"\\cysinf.000";
  51. String unattendPath = sysFolder + L"\\cysunat.000";
  52. // create the inf and unattend files for the oc manager
  53. do
  54. {
  55. if (infText.empty())
  56. {
  57. // sysoc.inf is in %windir%\inf
  58. infPath = Win::GetSystemWindowsDirectory() + L"\\inf\\sysoc.inf";
  59. }
  60. else
  61. {
  62. hr = CreateTempFile(infPath, infText);
  63. BREAK_ON_FAILED_HRESULT(hr);
  64. }
  65. hr = CreateTempFile(unattendPath, unattendText);
  66. BREAK_ON_FAILED_HRESULT(hr);
  67. String commandLine =
  68. String::format(
  69. IDS_SYSOC_COMMAND_LINE,
  70. sysFolder.c_str(),
  71. infPath.c_str(),
  72. unattendPath.c_str());
  73. DWORD exitCode = 0;
  74. hr = ::CreateAndWaitForProcess(commandLine, exitCode);
  75. BREAK_ON_FAILED_HRESULT(hr);
  76. // @@ might have to wait for the service to become installed as per
  77. // service manager
  78. if (exitCode == ERROR_SUCCESS)
  79. {
  80. result = true;
  81. break;
  82. }
  83. }
  84. while (0);
  85. LOG_BOOL(result);
  86. LOG_HRESULT(hr);
  87. return result;
  88. }