views:

168

answers:

1

Hello,

For some reason the Current Directory of my windows service is C:\Windows\System32 and when I schedule my service I get this error Access is Denied.

In one of the blogs I saw this peice to change the current directory. But I am not sure where to place this code.

Thanks

 System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory)
A: 

Depends on how your program depends[sic] on the current directory, but I'm sure where you need it is early in your service start up function, which would be OnStart(string[] args) in your service class that inherits from ServiceBase. Windows Services are initialized with CD set to what's specified on the service's settings.

Cecil Has a Name