I have a windows application, where I have retrieved AppData
using environment variable. So, it gives me following path
C:\document and settings\current user name\application data.
But, when I retrieve the AppData
path from windows service using environment variable, I get the following path:
C:\windows\ServiceProfiles\LocalService\AppData\Local
So, this AppData
path is different from my windows application environments variable's AppData
path.
I'm running windows service under local profile. I know that, if I change service profile to run under user, then service AppData
path and windows application AppData
path matches, but service prompts for username and password.
My question is how to get user AppData
path from service by running service under local profile without prompting for username and password?
Here is the Mohit shah's Answer:
I found out that is not possible to get user
AppData
path from windows service by running service under profile "LocalSystem". So, I usedEnvironment.SpecialFolder.CommomAppData
which gives me app data path
C:\ProgramData
, when run on windows 7 and when used same thing in windows service, it also gives the same path. I also ran the service under profile "LocalSystem", and it did not prompt me for credentials. This solved my problem.