Get appdata\\local folder path in C# windows service

蹲街弑〆低调 提交于 2019-12-03 01:40:48

Are you running the service under a user account? If not, the service will use its own profile as you see. If this service is "logged into" by a user, then you could pass the folder to the service and bypass local checking. Otherwise, try running the service under a user account (or create an account for it).

The AppData folder for each user is stored in the registry.

Using this path:

const string regKeyFolders = @"HKEY_USERS\<SID>\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders";
const string regValueAppData = @"AppData";

Given a variable sid string containing the users sid, you can get their AppData path like this:

string path=Registry.GetValue(regKeyFolders.Replace("<SID>", sid), regValueAppData, null) as string;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!