4

Is there any way to start a service using sc (or any other tool) on Windows and set its working directory to a different one than C:\Windows\system32 (which is the default one) ?

I know I can specify that in the service's source code but I am looking for a solution that doesn't involve modifying the service's source code.

3
  • Try setting the Service Properties to run the Service in compatibility mode. Otherwise you should not attempt to start the Service in a different location.
    – anon
    Commented Jun 10, 2022 at 14:11
  • Why not changing the working directory? Also, how will compatibility mode help? My issue is that i'm trying to use relative pathing in the source code but since its working directory is system32, it doesn't work. Commented Jun 10, 2022 at 14:14
  • 1
    Windows Services were meant to run in System32. You may wish to change your code to run that way.
    – anon
    Commented Jun 10, 2022 at 14:17

1 Answer 1

3

Services are started from an application called Service Control Manager. This application lives in the system directory %WinDir%\System32 and this is its current working directory.

When the system service is launched, it inherits by default all the attributes of the Service Control Manager and the parameters specified in the definition of the service.

Unfortunately, the current working directory is not one of those parameters, as you can see in the ChangeServiceConfigA function.

If you wish to change the current working directory of the service, you will need to do so from inside the service itself.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .