C# using Service account to access a file RRS feed

  • Question

  • I have a service account with read and write permissions on that folder.

    I created a windows forms desktop application and want to use that service account to access that folder. 

    How can i do that programmatically using C# etc . ?


    usher A

    Thursday, October 3, 2019 10:33 PM

All replies

  • Hi usher,

    Thank you for posting here.

    According to your description, I am not sure what is your service. Could you give a example about it? I also want to know where is your current environment.

    It will be better if you told me about it.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, October 4, 2019 6:35 AM
  • All Windows desktop programs run under the context of the logged-in user account. The desktop program such as Windows program would have to be started using an impersonation using your account in question to run under the context of your account you talk about.
    Friday, October 4, 2019 7:33 AM
  • You don't. A desktop app shouldn't run under the same account as a service unless you really need for it to be the same user. If you want to be able to read/write files to a folder from a service AND be able to read those files from other places then simply set the access rights on the folder/files to allow Users to read the folder/files. This is generally done when the folder is created and all children will inherit that right.

    Michael Taylor

    Friday, October 4, 2019 2:13 PM
  • Do you actually have a Service running under that Service account? Depending on what you want to do in your desktop application, you could have your Service read the data from a file/folder under its control and simply return the data to your desktop application.

    ~~Bonnie DeWitt [C# MVP]

    Friday, October 4, 2019 3:43 PM