Search code examples
.netwindows-services

What directory does a Windows Service run in?


I've created a very simple .NET Windows Service and installed it using InstallUtil.exe utility.

In the service I have a piece of code as such:

if (File.Exists("test_file.txt"))
{
   // Do something clever
}

I've created a file called test_file.txt in the same directory as the service but the commented part of the code is never being executed...?


Solution

  • Services are started from an application called Service Control Manager. This application lives in the system directory %WinDir%\System32

    On 64-bit versions of Windows 7+ this path is actually: %WinDir%\SysWOW64

    For more information see Service Control Manager at MSDN.