473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 8864
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
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
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
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
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
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
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
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
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
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
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.