1

I need to read some files from a mapped drive, I have to access this drive in a mapped way because it is outside the domain. This is troubling me because if I run my code as a Console application in C#, I can access it correctly, instead if I convert the same code to Windows service I can not: it throws me an exception in Event Viewer saying that the username and password are not correct. I've been looking information about but I couldn't find a clear answer.

I'm getting this from event viewer. "Access to the path is denied" enter image description here

I've tried to set my service to run as User account. also setting the credentials in ProjectInstaller class like this


serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.User;
            serviceProcessInstaller1.Username = "domain\\UserName";
            serviceProcessInstaller1.Password = "password";

maybe it is not possible to access?

Pino
  • 7,468
  • 6
  • 50
  • 69
Samir
  • 11
  • 2
  • 1
    Sounds like a simple permissions issue... You will have to run the service under an account that has access to the mapped drive or you will have to modify permissions on the mapped drive so that the account the service is running under has access. – phuzi May 09 '22 at 13:27
  • 2
    Does this answer your question? [Map a network drive to be used by a service](https://stackoverflow.com/questions/182750/map-a-network-drive-to-be-used-by-a-service) – jps May 09 '22 at 13:28
  • @phuzi I ran my service with credentials with an account with permissions. but as a service it didn't work. I don't know if there is a special configuration that i have to do. i'm still looking – Samir May 09 '22 at 16:23

0 Answers0