How to get the user name of the user who is associated with the current thread in C#

2 Answers

0 votes
using System;

class Program
{
    static void Main() {
        Console.WriteLine("UserName: {0}", Environment.UserName);
    }
}




/*
run:

UserName: root

*/

 



answered Nov 19, 2023 by avibootz
0 votes
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "UserName: " + Environment.UserName;
        }
    }
}




/*
run:
 
UserName: ABCD
  
*/

 



answered Nov 19, 2023 by avibootz

Related questions

...