473,659 Members | 2,886 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.Curre ntDomain.SetPri ncipalPolicy(Pr incipalPolicy.W indowsPrincipal )
Dim t As Thread = Thread.CurrentT hread
Dim p As Principal.Windo wsPrincipal = t.CurrentPrinci pal
Dim wi As Principal.Windo wsIdentity = p.Identity
Dim fullyQUserName As String = wi.Name

Thanks,
Christine
Jul 19 '05 #1
1 8887
Hi, Peter.

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

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

"hch_nguyen " <hc********@hot mail.com> wrote in message
news:e5******** ******@TK2MSFTN GP10.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.Curre ntDomain.SetPri ncipalPolicy(Pr incipalPolicy.W indowsPrincipal )
Dim t As Thread = Thread.CurrentT hread
Dim p As Principal.Windo wsPrincipal = t.CurrentPrinci pal
Dim wi As Principal.Windo wsIdentity = 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
2124
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 this: SomeRow = 'value'; But how do I set SomeRow to the row that the user is currently viewing?
4
3124
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 VS.net doesn't like the User.IsInRole("domain"); With the error "type or namspace for User not found". I can't work out which reference i'm missing! Basically the idea is to create a auth component that is called for
4
12454
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 object use the current users credentials if i use <identity impersonate="true" /> ? or do i have to set the Credentials property of the web request? If i do, how do i set it to be the current windows user logged into the application? I don't...
4
2412
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). The problem is that the user who "owns" the service is always the ASPNET account. That's not good since you don't see the actual application (because it's owned by ASPNET). I've tried changed the processmodel section in the machine.config file to...
4
5967
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 web.config file has authentication mode set to windows, and 'identity impersonate' is set to true. When I try and get the default.aspx page, IE returns an error page with an 'Access is denied.' error. (Even if I try direct from the webserver, logged...
6
4596
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 get the logged in username? Do I have to disable the anonymous access in IIS? I rather not because the site is running under a certain domain user which has access to certain folder and network shares and the site needs thsi access for reading...
8
4892
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 user's Name property in the WindowsPrincipal's IIdentity interface. Where can I find the role that the user is assigned for the current login? I only want the one role which is assigned for the current user, not all of
4
7113
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
15909
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 throught the application I can only see the user that started the thread. How can I see the user that is logged in?? I tried the following code: Private Function GetUser() As String
9
2998
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 of the current Windows user. I guess the name can be retrieved from the environment -- After I click the Start button of Windows, my name is on the very first line of the popup menu. So, this information is provided by the Windows
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8525
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
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 we have to send another system
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.