2

I'm developing a visual studio 2015 extension and I'm looking to get the identity of the user who's logged into the IDE (different to the user logged in to windows, or running devenv).

I can't figure out where (or if) I can get that information. It doesn't appear to be in the DTE object anywhere and googling around hasn't helped.

George Duckett
  • 31,770
  • 9
  • 95
  • 162

2 Answers2

1

Just the username

string username = System.Environment.UserName;

or

string adName = System.Environment.UserDomainName;

Full UserPrinciple

System.DirectoryServices.AccountManagement.UserPrincipal.Current

Most the normal .net methods for getting users from system or globals should work. All the AD namespaces (System.DirectoryServices) will also work as usual.

Also this regkey gets set at vs startup with the interactive user. enter image description here

Paul Swetz
  • 2,234
  • 1
  • 11
  • 28
  • Couldn't that be different to the identity that the user logs in as in the IDE (the identity shown top-right)? i.e. I might be running devenv as one user, but actually log in to it as someone else. – George Duckett Jul 11 '16 at 12:28
  • You would have to test that. I do know that the active vs running user gets set to the reg key I added to the answer. – Paul Swetz Jul 11 '16 at 12:30
  • 1
    Actually are you looking for the "Live ID" instead of the computer user, the one shown in the top right of VS is the Microsoft Id, which may or may not have anything to do with the computer user. – Paul Swetz Jul 11 '16 at 12:32
  • Yes, that's correct. Sorry the question wasn't clear. I'll edit to clarify. – George Duckett Jul 11 '16 at 12:33
  • 1
    Looks like that reg. key is what I'm after. Will leave this open for a bit in case there's a type-safe way of accessing it, but otherwise I'll accept. – George Duckett Jul 11 '16 at 12:38
  • 2
    On my pc I could only find this registry information: - HKEY_CURRENT_USER\Software\Microsoft\VSCommon\ConnectedUser\IdeUserV2\Cache I switch my Visual Studio 2019 login between two hotmail accounts and the data changed in this location. – ZedLepplin Jul 23 '19 at 10:25
-2

Code: C#

General: in header / above namespace MVC: Not sure about earlier version but 3 - 5 not required

using System.Security.Principal

function, property etc

string userid= User.Identity.Name.toString()