42

I have installed a C# Windows Service on Windows Server 2008. I installed it with InstallUtil. The service reads some data from the app.config file and it is doing it fine. Can you tell me where this file is located after installing the service? I have been looking for hours but can't find it.

Mité
  • 1,066
  • 3
  • 14
  • 25

6 Answers6

62

You can verify the exact location of the installed Windows Service by following the steps below:

  1. Bring up the list of Windows Services by clicking the "Services" icon under the "Administrative Tools" icon. You can also get this list by typing "View local services" in the Search Menu under the Start Menu.

  2. Select your Windows service in the list of installed services, right-click and then select Properties. You can also double click on row representing the service.

  3. Locate the "Path to executable" value on the Properties dialog box. The value will include any command line parameters.

  4. Open the folder in which the service executable resides.

If the Windows service has been built with .NET Framework, its configuration will be stored in the corresponding .config file, i.e., the name of the executable suffixed by ".config", e.g., if the name of the executable is "XyzService.exe", then the name of the .config file will be "XyzService.exe.config".

A couple of things to note:

  • If you installed the service after building it on the same machine using say, Visual Studio, then Visual Studio would have transformed the App.config file from the project and placed it in the build output folder automatically (and renamed it appropriately using the above naming convention).

  • If your machine is set to hide file extensions in Windows Explorer, you will see 2 files "XyzService" and "XyzService.exe". In this case, the "XyzService.exe" is your config file. If you then switch off the option to hide file extenions in Windows Explorer, you will then begin to see "XyzService.exe" and "XyzService.exe.config".

  • If you cannot find a corresponding .exe.config file, then it is possible that the code within the service is falling back to default values. In this case, you can place a properly named and formatted config file alongside the service executable and then restart the service and everything should be fine.

Umar Farooq Khawaja
  • 3,805
  • 1
  • 28
  • 50
  • 2
    Great Answer. Just what I needed. I looked and sure enough my config file was missing. once i placed it in the same location as EXE - Service was able to start. Thanks soo much. Saved my day! – Paula Mar 07 '13 at 19:59
  • Also wrong (or at least incomplete). After hitting my head on all walls I found that my service was using a configuration file which was in C:\Windows\SysWOW64\config\systemprofile\AppData\Local\%MyCompanyName% and it was renamed (as is the rule for other .NET apps) user.config. – Gogu CelMare Apr 20 '18 at 02:30
4

According to Microsoft

For client executables, the application configuration file resides in the same directory as the application's executable and has the same base name as the executable with a .config extension.

Note, if your exe is called appname.exe, and you have Windows explorer set to hide extensions, then your application will display as appname and your config file then it will be displayed as appname.exe (even though the true name is appname.exe.config)

As others have pointed out, InstallUtil doesn't do anything with the config file and it should have copied to the server in the same manner as the exe itself.

sgmoore
  • 14,470
  • 5
  • 37
  • 65
3

It is the same location from where you have registered service using installutil tool.

Tilak
  • 27,830
  • 17
  • 73
  • 125
  • I installed it from System32 folder, but there is no file there that resembles an app.config file – Mité Dec 28 '12 at 19:25
  • It will be .exe.config. For example if service application is abc.exe, config will be abc.exe.config – Tilak Dec 28 '12 at 19:25
  • 1
    mitte check if Windows Explorer is set to hide file extensions, if so look for ServiceName.exe, rather than ServiceName.exe.config. – Umar Farooq Khawaja Dec 28 '12 at 19:46
2

The App.config is likely called {ProjectName}.exe.config given the fact that it is a Windows Service. Check to see if that file exists and is what you are looking for.

Brandon
  • 9,812
  • 15
  • 59
  • 95
1

The same place where your application (Windows Service) is.

Check it out, if it's not there place it in the same directory as of service.

Kishore Kumar
  • 11,843
  • 26
  • 86
  • 149
  • 1
    installUtil is just a tool to install, it will not change the location of your app.config. It just registers the windows service – Kishore Kumar Dec 28 '12 at 19:23
0

If you have a live environment (and from your question it seems like you do), you can check what's actually happening using the superior Process Monitor utility. But usually the .config fileis located right next to the .exe, and named the same.