0

I want to get the Environment.SpecialFolder.ApplicationData of all users from windows service installed as a local system with admin privileges.

Example:

If I have Tom, Matt and Christine users, I need:

C:\Users\Matt\AppData\Local

C:\Users\Tom\AppData\Local

C:\Users\Christine\AppData\Local

Thanks in advance!

Community
  • 1
  • 1
  • First have a look at [this question](http://stackoverflow.com/questions/2299100/windows-7-how-can-i-get-a-list-of-all-windows-user-names-in-net) – helb Oct 24 '13 at 09:46

1 Answers1

0

Below is the code by which you can find out the ApplicationData path for any user -

  1. First find out the name of the current user.
  2. Find out the Application Data path.
  3. Now replace the current users name from application data path.

    /// <summary>
    /// GetAppDatafolder
    /// </summary>
    private static void GetAppDatafolder(string otherUserName)
    {
        var currentUserIdentity = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
        var currentUserName = (currentUserIdentity.Contains(@"\")) ? (currentUserIdentity.Split('\\')[1]) : currentUserIdentity;
        var currentAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
        var otherUserAppDataPath = currentAppDataPath.Replace(currentUserName, otherUserName);
    
        Console.WriteLine(string.Format("Current User AppDataPath : {0}", currentAppDataPath));
        Console.WriteLine(string.Format("{0} AppDataPath : {1}", otherUserName, otherUserAppDataPath));
    }
    
a1ashiish
  • 81
  • 4