check active user on XP S.O

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I would like to know, how can I check the name of the current user that is
Log on in O.S XP.
Hi already try the

Environment.UserName.ToString();
but is not what i would like to appear,its abreviated,
like 'MJhonson', and and what i want is the complete name 'Michael Johnson'.
 
Hello Pedro,

Use active directory for this

There are http://groups.google.com/groups/search?q=dotnet+active+directory+full+name
some threads where this topic was discussed

P> Hi all,
P>
P> I would like to know, how can I check the name of the current user
P> that is
P> Log on in O.S XP.
P> Hi already try the
P> Environment.UserName.ToString();
P> but is not what i would like to appear,its abreviated,
P> like 'MJhonson', and and what i want is the complete name 'Michael
P> Johnson'.
P> Pedro
P>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
You can get the full name from Active Directory something like this:

using System.DirectoryServices;
string DomainUser =
System.Security.Principal.WindowsIdentity.GetCurrent().Name.Replace("\","/");
DirectoryEntry ADEntry = new DirectoryEntry("WinNT://" + DomainUser);
string FullName = ADEntry.Properties("FullName").Value;

Or you can use P/Invoke to call the Win32 API:

[DllImport("Secur32.dll", CharSet = CharSet.Auto)]
static extern short GetUserNameEx (int nameFormat, StringBuilder
lpNameBuffer, ref int size);

int size = 1000;
StringBuilder bldr = new StringBuilder(size);
GetUserNameEx(3, bldr, ref size);
 
Hi

My code is :

string DomainUser =

System.Security.Principal.WindowsIdentity.GetCurrent().Name.Replace(@"\","/");
DirectoryEntry ADEntry = new DirectoryEntry("WinNT://" +
DomainUser);
string FullName = ADEntry.Properties("FullName").value;
MessageBox.Show("FullName");

The error is :

Error 1 'System.DirectoryServices.DirectoryEntry.Properties' is a 'property'
but is used like a 'method'


--
Thanks ,

Pedro


Chris Fulstow said:
You can get the full name from Active Directory something like this:

using System.DirectoryServices;
string DomainUser =
System.Security.Principal.WindowsIdentity.GetCurrent().Name.Replace("\","/");
DirectoryEntry ADEntry = new DirectoryEntry("WinNT://" + DomainUser);
string FullName = ADEntry.Properties("FullName").Value;

Or you can use P/Invoke to call the Win32 API:

[DllImport("Secur32.dll", CharSet = CharSet.Auto)]
static extern short GetUserNameEx (int nameFormat, StringBuilder
lpNameBuffer, ref int size);

int size = 1000;
StringBuilder bldr = new StringBuilder(size);
GetUserNameEx(3, bldr, ref size);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top