Hi,
To get the user name separately you can import the dll file Advapi32.dll.
See the following code,
using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication2
{
class Class1
{
[STAThread]
[DllImport("Advapi32.dll", EntryPoint="GetUserName", ExactSpelling=false,
SetLastError=true)]
static extern bool GetUserName(
[MarshalAs(UnmanagedType.LPArray)] byte[] lpBuffer,
[MarshalAs(UnmanagedType.LPArray)] Int32[] nSize );
static void Main(string[] args)
{
byte[] str=new byte[256];
Int32[] len=new Int32[1];
len[0]=256;
GetUserName(str,len);
Console.WriteLine(System.Text.Encoding.ASCII.GetSt ring(str));
Console.ReadLine();
}
}
}
Regards, Daya PSP India
"Zest4Csharp" wrote:
Hi there,
When i use:
WindowsIdentity.GetCurrent().Name.ToString();
I get a concatenated domain name and user name in the format :
DOMAIN\USER_NAME.
Are there functions in C# to get the domain name and user name separately?
Cheers
Zest