473,503 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get current windows user

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(Princip alPolicy.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
Jul 19 '05 #1
1 8869
Hi, Peter.

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

Thanks!
Christine
"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:#v**************@TK2MSFTNGP12.phx.gbl...
How about using the WindowsIdentity.GetCurrent() method. This always works for me.

"hch_nguyen" <hc********@hotmail.com> wrote in message
news:e5**************@TK2MSFTNGP10.phx.gbl...
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(Princip alPolicy.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


Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2114
by: Christopher Weaver | last post by:
I want to set a value in a specific field in the current row of a DataSet. This seems like the most basic thing to do but I can't find the syntax for identifying the current row. IOW, I can do...
4
3114
by: Mark | last post by:
hey, i'm trying to get the current windows user and the groups they are in. Intergrated windows auth on and annoymous access turned off on IIS. However when trying to compile the following code...
4
12423
by: Jamie | last post by:
I'm trying to create a HttpWebRequest object that uses the current logged in users credentials. The site is using Windows Authentication, Anonymous access is turned off. Will the HttpWebRequest...
4
2400
by: Kristof Despiere | last post by:
Suppose you have one domain, filled with a couple of users. What needs to be done now is I need to start a windows application from a webform by pressing a button on the webform (for example). ...
4
5959
by: Nick | last post by:
I'm developing an intranet app, and want to get the current user name for logging purposes. I've turned off anonymous access, and turned on windows authentication in the IIS config. The apps...
6
4582
by: John Dalberg | last post by:
I want to automate the process of logging into an intranet. I want to pull out the username of the Windows user logged into the machine running the browser and use the username in my app. How can I...
8
4883
by: Mark White | last post by:
Hey everyone I'm having a great deal of problems finding this information through google and yahoo, so I turn to you on this. I have a Windows app running on XP. I am able to caputre the...
4
7104
by: Leszek | last post by:
Hello! I have my webpage (ASP) in domain (IIS 6.0). I need to make a popup with fullname of current user. How can I do this? Maybe someone have any examples? Thanks!
3
15890
by: Lattis | last post by:
I have the following problem: User A is logged in to a windows 2000 terminal. He runs an application which runs under the credentials of a different user. If I try to see the current user...
9
2992
by: Alex | last post by:
Get the Name and Phone Number of the Current Windows User in a .NET Application I am writing a simple .NET (C#) application. It needs to "automatic" get the Name (last, first) and phone number...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.