2

Using C#, is it possible to create an IPrincipal User from a string username? I think my question is as simple at that :).

farina
  • 3,486
  • 6
  • 32
  • 44

1 Answers1

2

I believe you can do something like this:

WindowsPrincipal pFoo = new WindowsPrincipal(new WindowsIdentity("domain\user"));
Brian Desmond
  • 4,473
  • 1
  • 13
  • 11
  • 1
    I think that needs escaped like "domain\\user", but that returns "The name provided is not a properly formed account name." – farina Mar 22 '12 at 22:47
  • 1
    Nice, it's just NT username. So WindowsPrincipal pFoo = new WindowsPrincipal(new WindowsIdentity("user")); works! – farina Mar 22 '12 at 23:30
  • @farina [here](https://stackoverflow.com/questions/5933643/create-windowsidentity-using-just-a-domain-and-username) is the solution to the exception you are getting – RBT Jul 04 '17 at 12:48