elevation_service.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <windows.h>
  5. #include "base/at_exit.h"
  6. #include "base/command_line.h"
  7. #include "base/logging.h"
  8. #include "base/process/memory.h"
  9. #include "base/win/process_startup_helper.h"
  10. #include "base/win/scoped_com_initializer.h"
  11. #include "chrome/elevation_service/service_main.h"
  12. #include "chrome/install_static/product_install_details.h"
  13. extern "C" int WINAPI wWinMain(HINSTANCE instance,
  14. HINSTANCE prev_instance,
  15. wchar_t* command_line,
  16. int show_command) {
  17. // Initialize the CommandLine singleton from the environment.
  18. base::CommandLine::Init(0, nullptr);
  19. logging::LoggingSettings settings;
  20. settings.logging_dest =
  21. logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR;
  22. logging::InitLogging(settings);
  23. // The exit manager is in charge of calling the dtors of singletons.
  24. base::AtExitManager exit_manager;
  25. install_static::InitializeProductDetailsForPrimaryModule();
  26. // Make sure the process exits cleanly on unexpected errors.
  27. base::EnableTerminationOnHeapCorruption();
  28. base::EnableTerminationOnOutOfMemory();
  29. base::win::RegisterInvalidParamHandler();
  30. base::win::SetupCRT(*base::CommandLine::ForCurrentProcess());
  31. // Initialize COM for the current thread.
  32. base::win::ScopedCOMInitializer com_initializer(
  33. base::win::ScopedCOMInitializer::kMTA);
  34. if (!com_initializer.Succeeded()) {
  35. PLOG(ERROR) << "Failed to initialize COM";
  36. return -1;
  37. }
  38. // Run the COM service.
  39. elevation_service::ServiceMain* service =
  40. elevation_service::ServiceMain::GetInstance();
  41. if (!service->InitWithCommandLine(base::CommandLine::ForCurrentProcess()))
  42. return -1;
  43. return service->Start();
  44. }