0

I wrote a service and in the code I tried to get the AppData folder's path:

C:\Users\[Username]\AppData\

I tried:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

But I got:

C:\Windows\system32\config\systemprofile\AppData
Grant Winney
  • 65,241
  • 13
  • 115
  • 165
bunny
  • 1,797
  • 8
  • 29
  • 58

1 Answers1

1

You're getting the AppData folder of the Account running the service. (System Account) There is no other user involved in it.

If you want a particular user's AppData folder, run the Windows Service under that user's account.

Raja Nadar
  • 9,409
  • 2
  • 32
  • 41
  • I searched online and found to run the windows services under a user account, I need to specify the username and the password. I would like to know how I can get the username and password of the currently log in user? – bunny Apr 06 '14 at 15:07
  • You cannot get it from code. You need to be the current user and know it. Once you know you can set it in windows service properties or from code. – Raja Nadar Apr 06 '14 at 15:12