Search code examples
c#configuration.net-3.5impersonationsettings

Access other user's local application settings in C#


I have WPF application, let's say Application1, run under User1. I need to access user scoped settings of User2 in AppData folder for Application2.

So, what's really happening is this:

  • User1 is logged in user, in windows
  • User1 is actually person associated with account User2
  • User1 starts Application1
  • Application1 asks for credentials to ensures User1 starts application (see next bullet) as appropriate user (User2 in this case)
  • Now, Application1 should run Application2 with provided credentials, but before that, it should check User2 settings for Application2

How can I do that without running Application1 as User2?

If I can change process owner for Application1 at run time to do that, that would also be acceptable solution.


Solution

  • I ended up running another custom made console program under User2 which reads settings file as XmlDocument.

    Reading settings file:

    if (File.Exists(settingsPath))
    {
        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.Load(settingsPath);
        XmlNode settingsNode = xmlDocument.SelectSingleNode("/XPath.to.node.you.are.looking.for");
        foreach(XmlNode xmlNode in settingsNode.ChildNodes)
        {
            //do some work
        }
    }