list all local users using directory services

后端 未结 2 1428
梦如初夏
梦如初夏 2021-02-06 02:26

The following method I created seem does not work. An error always happens on foreach loop.

NotSupportedException was unhandled...The provider does not su

2条回答
  •  情歌与酒
    2021-02-06 03:04

    The following are a few different ways to get your local computer name:

    string name = Environment.MachineName;
    string name = System.Net.Dns.GetHostName();
    string name = System.Windows.Forms.SystemInformation.ComputerName;
    string name = System.Environment.GetEnvironmentVariable(“COMPUTERNAME”);
    

    The next one is a way to get the current user name:

    string name = System.Windows.Forms.SystemInformation.UserName;
    

提交回复
热议问题