0

I want to get the e-mail address of the user that is currently logged on to Visual studio, in debug mode of course. Just like getting windows account name using Environment.UserName.

is that possible?

  • Why do you want to do this? – mjwills Nov 23 '17 at 12:06
  • 1
    From where? From a Visual Studio extension is reasonable. From any arbitrary program that happens to be debugged by VS is not -- that would cross a process boundary from debuggee to debugger and possibly cause deadlocks, aside from the potential issues for abuse. – Jeroen Mostert Nov 23 '17 at 12:07

1 Answers1

1

I would never use the VisualStudio username for a licensing system. The name of the user of VS is stored in a simple registry key and can be easily manipulated.

You can retrieve the username/account information for the most Visual Studio versions up to 14 (Visual Studio 2015) with the following code. Visual Studio 2017 has a different registry path. Read more about it here.

const byte minVSVersion=11; // Visual Studio 2012
const byte maxVSVersion=14; // Visual Studio 2015

static List<string> getVSUsers()
{
    var vsUsrs=new List<string>();
    for(byte version=minVSVersion; version<=maxVSVersion; version++)
        vsUsrs.Add((string)Registry.GetValue(
            @"HKEY_USERS\.DEFAULT\Software\Microsoft\VisualStudio\"+version+@".0_Config\Registration",
            "UserName", null));

    return vsUsrs.Where(usr => usr!=null).ToList();
}

Unfortunately, it is not possible to determine exactly which VisualStudio version the user used to compile the program.

Boslx
  • 81
  • 6