Mohit Shah Mohit Shah - 9 months ago 128
C# Question

Get user appdata path from windows service by running service under local profile

I have a windows application. In that 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 following path

c:\windows\ServiceProfiles\LocalService\AppData\Local

so this appdata path is different from appdata path that i got from windows application environments variable 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.

so my question is how to get user appdata path from service by running service under local profile without prompting for username and password?

Answer Source

I have also encountered in that problem and looked at your question but i at first sight didnot find an answer in it.

This is the Mohit shah Answer

"I found out that is not possible to get user appdata path from windows service by running service under profile "LocalSystem". So I used Environment.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 gived the same path and i also ran the service under profile "LocalSystem" so it did not prompt me for credentials. So this solved my problem."

@Mohit Shah Please mark this is as answer so that other can take help from that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download