Get current windows user

H

hch_nguyen

I am developing in the .NET Framework using vb.net running under Windows
2000 SP2. I have a snippet of code that runs to determine the name of the
current windows user logged in. The code works fine when I run it logged in
as a local administrator on the local machine, in other words not logged
into any domain on our network. However, when I log in to the domain on the
same machine, also as local administrator as well as domain admin, the
snippet of code is unable to determine the current user. It errors out. It
gives back just a generic identity as opposed to a window's identity. My
code follows below.

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
Dim t As Thread = Thread.CurrentThread
Dim p As Principal.WindowsPrincipal = t.CurrentPrincipal
Dim wi As Principal.WindowsIdentity = p.Identity
Dim fullyQUserName As String = wi.Name

Thanks,
Christine
 
C

Christine Nguyen

Hi, Peter.

Yes, I tried something similar right after I posted and it worked.

Thanks!
Christine
 

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

Top