hello,
I'm new to C# and in the early stages of learning. I have the following code that retrieves the domain and user. I like to remove the domain from the string result leaving only the user name
This is what I get
This is what I like to get
Thanks for any help with this
I'm new to C# and in the early stages of learning. I have the following code that retrieves the domain and user. I like to remove the domain from the string result leaving only the user name
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System;
using System.Security.Principal;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Microsoft.Win32.RegistryKey key;
private void Form1_Load(object sender, System.EventArgs e)
{
string sCurrentUser;
sCurrentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
label1.Text = sCurrentUser;
}
}
}
This is what I get
Code:
Domain\UserName
This is what I like to get
Code:
UserName
Thanks for any help with this