【C#】ユーザ情報取得 ~ コンピュータ名 etc ~

■ コンピュータ名 / マシン名

構文

Environment.MachineName

■ ユーザ名

構文

Environment.UserName;

サンプル

http://www.atmarkit.co.jp/fdotnet/dotnettips/642displayname/displayname.html
を参照のこと
private string GetFullName()
{
    // ドメイン名
    string domain = Environment.UserDomainName;
    // ユーザ名
    string userName = Environment.UserName;

    string path = string.Format("WinNT://{0}/{1}", domain, userName);

    string fullName;
    using (var directoryEntry = new DirectoryEntry(path))
    {
        // フル・ネーム
        fullName = directoryEntry.Properties["FullName"].Value.ToString();
    }

    return fullName;
}

private void button18_Click(object sender, EventArgs e)
{
    this.label1.Text = this.GetFullName();
}

ドメインの名前

 * PCがドメインに参加していない場合にはコンピュータ名

構文

Environment.UserDomainName;

■ フル・ネーム

構文

string fullName = string.Empty;
using (DirectoryEntry dirEnt = new DirectoryEntry(path))
{
    string.Format(
        "WinNT://{0}/{1}"
         Environment.UserDomainName // ドメイン名
        , Environment.UserName); // ユーザ名
    fullName = dirEnt.Properties["FullName"].Value.ToString();
}

■ サンプル

private void button6_Click(object sender, EventArgs e)
{
    this.label1.Text = Environment.UserDomainName; // ドメイン名
    this.label2.Text = Environment.UserName;       // ユーザー名

    string path = string.Format(
        "WinNT://{0}/{1}"
        , Environment.UserDomainName
        , Environment.UserName);
    using (DirectoryEntry dirEnt = new DirectoryEntry(path))
    {
      // フル・ネーム
      this.label3.Text = dirEnt.Properties["FullName"].Value.ToString();
    }
}


関連記事

特殊ディレクトリのパスを取得する ~ ユーザのプロファイルフォルダ etc ~

https://blogs.yahoo.co.jp/dk521123/37974899.html

C#IPアドレス に関する処理

https://blogs.yahoo.co.jp/dk521123/30136955.html

C#】色々なプロパティ ~ Environment / Application ~

https://blogs.yahoo.co.jp/dk521123/20158603.html

【JS】ユーザ情報取得

https://blogs.yahoo.co.jp/dk521123/37924793.html