1

I have a window service that needs to access a shared folder to check a file. Currently I use:

        if (System.IO.File.Exists(excelFile))

where excelFile is: \\isgisdb01\GIS_projects\Garage_sales\GarageSales.xls

That results in an error: file not found

So I added a service account to the Garage_sales folder. How do I assign the service account credentials to my code so it would get the permission it needs?

Anders Abel
  • 67,989
  • 17
  • 150
  • 217
bach dang
  • 185
  • 5
  • 20
  • You can do it using impersonate [See this][1] for how to impersonate in .Net [1]: http://stackoverflow.com/questions/125341/how-do-you-do-impersonation-in-net – Hitesh Dec 31 '13 at 18:09
  • I got it to work using your advice. Thanks – bach dang Dec 31 '13 at 20:11

1 Answers1

3

You do that through the service control manager where you tell the service under what credentials to execute.

rerun
  • 25,014
  • 6
  • 48
  • 78
  • I went into the property of the window service and change from Local System to the service account that I just created, but I don't think that makes sense. Can I just leave it as Local System and supply the credentials when I access the file? – bach dang Dec 31 '13 at 16:59
  • You can but you will need to impersonate that account before you attempt to access the file. – rerun Dec 31 '13 at 17:03