I am writing a service where I need to get the AppData \ Roaming folder. I use the following construction Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); But I get the following value: C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\ But if I run the console application and do the same thing, I get the right result. Can someone please explain what's wrong. I fight for several hours over the problem and cannot solve it at all.
- And nothing that each user's AppData folder has its own? - Pavel Mayorov
- @PavelMayorov and nothing, that in one application one value, and in the second another with the same use of the same methods? - Oleg Lylok
- 2This is normal when they run on behalf of different users. - Pavel Mayorov
- @PavelMayorov then how do I get AppData \ Roaming when starting from NT AUTHORITY \ SYSTEM? - Oleg Lylok
- one@OlegLylok so you got it. See, there are AppData and Roaming on the way ... - Pavel Mayorov pm
|
1 answer
C:\WINDOWS\system32\config\systemprofile is the profile path for the SYSTEM user. If you need a profile of another user, start the service on his behalf, or find the path for a specific user (SYSTEM has enough rights for that). This can be done something like this:
Get user token through LogonUser
Load his profile via LoadUserProfile
Get the path to the desired folder using SHGetKnownFolderPath , passing it the received token
|