0

Using UseWindowsService to host asp.net core as a Windows service, is there a reliable way of understanding if the application is indeed running as a Windows service or as a console application? I'm asking because in one case (console) GetCurrentDirectory returns the correct current folder while in the other (Windows service) it always returns the "x:\WINDOWS\system32" folder.

whatever
  • 2,492
  • 6
  • 30
  • 42

2 Answers2

1

See this Answer

Use System.IO.Path.GetDirectoryName(Application.ExecutablePath) for a more reliable way to get the current folder for Windows Services or Console apps.

Bryan Williams
  • 452
  • 1
  • 5
  • 17
1

I found the answer myself, WindowsServiceHelpers.IsWindowsService() returns exactly what I need, information as to if a windows service or a console application is running.

whatever
  • 2,492
  • 6
  • 30
  • 42