console.cpp 829 B

12345678910111213141516171819202122232425262728
  1. #include "nssm.h"
  2. /* See if we were launched from a console window. */
  3. bool check_console() {
  4. /* If we're running in a service context there will be no console window. */
  5. HWND console = GetConsoleWindow();
  6. if (! console) return false;
  7. unsigned long pid;
  8. if (! GetWindowThreadProcessId(console, &pid)) return false;
  9. /*
  10. If the process associated with the console window handle is the same as
  11. this process, we were not launched from an existing console. The user
  12. probably double-clicked our executable.
  13. */
  14. if (GetCurrentProcessId() != pid) return true;
  15. /* We close our new console so that subsequent messages appear in a popup. */
  16. FreeConsole();
  17. return false;
  18. }
  19. void alloc_console(nssm_service_t *service) {
  20. if (service->no_console) return;
  21. AllocConsole();
  22. }