Eze Ahuna Eze Ahuna - 1 year ago 86
C# Question

Get environment variable of another user?

I have a windows service program that saves files in the application data folder of the local system user.I also have a windows form that needs to read those files and runs on different user accounts but I don't know how to get the environment variable of another user, specifically the local system. If it is possible i would appreciate an example, thank you in advance.

Answer Source

Just call Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); and make a subfolder within the folder it returns to store your files. That location is designed to be the non user specific data storage location.

The default location is C:\ProgramData but you should use the function to get it instead of hardcoding the path. Also you can't save files in the root of that folder but you can make subfolders and save your files in that.

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