|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Getting current user nameHow can I get the login name of the user currently logged into Windows as a
string? Thanks, Steve Enzer Hi Steve,
System.Environment.UserName -- Show quoteHide quoteBest regards, Carlos J. Quintero MZ-Tools: Productivity add-ins for Visual Studio You can code, design and document much faster: http://www.mztools.com "Steve Enzer" <nospam@nospam.com> escribió en el mensaje news:e1L3XNxMGHA.1124@TK2MSFTNGP10.phx.gbl... > How can I get the login name of the user currently logged into Windows as > a string? > > Thanks, > Steve Enzer > "Carlos J. Quintero [VB MVP]" <carlosq@NOSPAMsogecable.com> wrote in message news:OpKmARxMGHA.3720@TK2MSFTNGP10.phx.gbl... How simple. Ive been using> Hi Steve, > > System.Environment.UserName System.Security.Principal.WindowsIdentity.GetCurrent().Name -- Show quoteHide quoteAl Reid > > -- > > Best regards, > > Carlos J. Quintero > Well, in .NET 2.0 is simpler: My.User.Name, although it returns the domain
too. -- Show quoteHide quoteBest regards, Carlos J. Quintero MZ-Tools: Productivity add-ins for Visual Studio You can code, design and document much faster: http://www.mztools.com "Al Reid" <arei***@reidDASHhome.com> escribió en el mensaje news:OvpF1XxMGHA.740@TK2MSFTNGP12.phx.gbl... > "Carlos J. Quintero [VB MVP]" <carlosq@NOSPAMsogecable.com> wrote in > message news:OpKmARxMGHA.3720@TK2MSFTNGP10.phx.gbl... >> Hi Steve, >> >> System.Environment.UserName > > How simple. Ive been using > System.Security.Principal.WindowsIdentity.GetCurrent().Name > FYI, the My.User.Name functionality does not work for a console app.
Show quoteHide quote "Carlos J. Quintero [VB MVP]" <carlosq@NOSPAMsogecable.com> wrote in message news:%23CKTJbxMGHA.2696@TK2MSFTNGP14.phx.gbl... > Well, in .NET 2.0 is simpler: My.User.Name, although it returns the domain > too. > > -- > > Best regards, > > Carlos J. Quintero > > MZ-Tools: Productivity add-ins for Visual Studio > You can code, design and document much faster: > http://www.mztools.com > > > > "Al Reid" <arei***@reidDASHhome.com> escribió en el mensaje > news:OvpF1XxMGHA.740@TK2MSFTNGP12.phx.gbl... >> "Carlos J. Quintero [VB MVP]" <carlosq@NOSPAMsogecable.com> wrote in >> message news:OpKmARxMGHA.3720@TK2MSFTNGP10.phx.gbl... >>> Hi Steve, >>> >>> System.Environment.UserName >> >> How simple. Ive been using >> System.Security.Principal.WindowsIdentity.GetCurrent().Name >> > The My namespace doesn't exist for console applications.
Show quoteHide quote "Joe Sutphin" <joesutp***@earthlink.net> wrote in message news:uZjoKJyMGHA.420@tk2msftngp13.phx.gbl... > FYI, the My.User.Name functionality does not work for a console app. > > "Carlos J. Quintero [VB MVP]" <carlosq@NOSPAMsogecable.com> wrote in > message news:%23CKTJbxMGHA.2696@TK2MSFTNGP14.phx.gbl... >> Well, in .NET 2.0 is simpler: My.User.Name, although it returns the >> domain too. >> >> -- >> >> Best regards, >> >> Carlos J. Quintero >> >> MZ-Tools: Productivity add-ins for Visual Studio >> You can code, design and document much faster: >> http://www.mztools.com >> >> >> >> "Al Reid" <arei***@reidDASHhome.com> escribió en el mensaje >> news:OvpF1XxMGHA.740@TK2MSFTNGP12.phx.gbl... >>> "Carlos J. Quintero [VB MVP]" <carlosq@NOSPAMsogecable.com> wrote in >>> message news:OpKmARxMGHA.3720@TK2MSFTNGP10.phx.gbl... >>>> Hi Steve, >>>> >>>> System.Environment.UserName >>> >>> How simple. Ive been using >>> System.Security.Principal.WindowsIdentity.GetCurrent().Name >>> >> > > "AMDRIT" <amd***@hotmail.com> schrieb: Well, with conditional compilation constants it's maybe possible to add it > The My namespace doesn't exist for console applications. to console applications too, but I fear that this would be justifiable only for using a simple method which is mainly a wrapper around .NET Framework methods. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> No, duh !
Show quoteHide quote "AMDRIT" <amd***@hotmail.com> wrote in message news:ePNxva0MGHA.1532@TK2MSFTNGP12.phx.gbl... > The My namespace doesn't exist for console applications. > > "Joe Sutphin" <joesutp***@earthlink.net> wrote in message > news:uZjoKJyMGHA.420@tk2msftngp13.phx.gbl... >> FYI, the My.User.Name functionality does not work for a console app. >> >> "Carlos J. Quintero [VB MVP]" <carlosq@NOSPAMsogecable.com> wrote in >> message news:%23CKTJbxMGHA.2696@TK2MSFTNGP14.phx.gbl... >>> Well, in .NET 2.0 is simpler: My.User.Name, although it returns the >>> domain too. >>> >>> -- >>> >>> Best regards, >>> >>> Carlos J. Quintero >>> >>> MZ-Tools: Productivity add-ins for Visual Studio >>> You can code, design and document much faster: >>> http://www.mztools.com >>> >>> >>> >>> "Al Reid" <arei***@reidDASHhome.com> escribió en el mensaje >>> news:OvpF1XxMGHA.740@TK2MSFTNGP12.phx.gbl... >>>> "Carlos J. Quintero [VB MVP]" <carlosq@NOSPAMsogecable.com> wrote in >>>> message news:OpKmARxMGHA.3720@TK2MSFTNGP10.phx.gbl... >>>>> Hi Steve, >>>>> >>>>> System.Environment.UserName >>>> >>>> How simple. Ive been using >>>> System.Security.Principal.WindowsIdentity.GetCurrent().Name >>>> >>> >> >> > > Is there also a (simple) way to have Windows authenticate a Username /
Password combination? I need that for an application security lock (after xxx minutes of inactivity) Show quoteHide quote "Carlos J. Quintero [VB MVP]" <carlosq@NOSPAMsogecable.com> wrote in message news:%23CKTJbxMGHA.2696@TK2MSFTNGP14.phx.gbl... > Well, in .NET 2.0 is simpler: My.User.Name, although it returns the domain > too. > > -- > > Best regards, > > Carlos J. Quintero > > MZ-Tools: Productivity add-ins for Visual Studio > You can code, design and document much faster: > http://www.mztools.com > > > > "Al Reid" <arei***@reidDASHhome.com> escribió en el mensaje > news:OvpF1XxMGHA.740@TK2MSFTNGP12.phx.gbl... >> "Carlos J. Quintero [VB MVP]" <carlosq@NOSPAMsogecable.com> wrote in >> message news:OpKmARxMGHA.3720@TK2MSFTNGP10.phx.gbl... >>> Hi Steve, >>> >>> System.Environment.UserName >> >> How simple. Ive been using >> System.Security.Principal.WindowsIdentity.GetCurrent().Name >> > Hi,
Imports System.Security Imports System.Security.Principal AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal) Dim myID As WindowsIdentity = WindowsIdentity.GetCurrent() Msgbox("The Current User is : " & myID.Name) Regards, Cerebrus. I saw your post just now and have a question, Carlos.
The definition of the Environment.Username property suggests that it would get the name of the User who launched the current thread or process. Now, in some cases, that username could be SYSTEM or LOCALSERVICE or NETWORKSERVICE. But I think that the WindowsIdentity name would always be the name of the currently logged on user. Please tell me if I am right (or correct me if I'm wrong ! ), and if so, then Environment.Username would not be such a good method of getting this information, after all. Thanks, Cerebrus. Hi,
Yes, Environment.Username makes internally a call to the Win32 API function GetUserName and according to the docs (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getusername.asp) it retrieves the user associated with the current thread. So, in most cases it will do the trick but if you are calling it from a Windows service it won´t do the trick, although it doesn´t make much sense to do it from a Windows service (by definition)... -- Show quoteHide quoteBest regards, Carlos J. Quintero MZ-Tools: Productivity add-ins for Visual Studio You can code, design and document much faster: http://www.mztools.com "Cerebrus99" <zorg***@sify.com> escribió en el mensaje news:1140108221.805677.95260@g43g2000cwa.googlegroups.com... >I saw your post just now and have a question, Carlos. > > The definition of the Environment.Username property suggests that it > would get the name of the User who launched the current thread or > process. Now, in some cases, that username could be SYSTEM or > LOCALSERVICE or NETWORKSERVICE. > > But I think that the WindowsIdentity name would always be the name of > the currently logged on user. > > Please tell me if I am right (or correct me if I'm wrong ! ), and if > so, then Environment.Username would not be such a good method of > getting this information, after all. > > Thanks, > > Cerebrus. > Imports System.Security.Principal
'Get the current identity and put it into an identity object. Dim MyIdentity As WindowsIdentity = WindowsIdentity.GetCurrent() 'Put the previous identity into a principal object. Dim MyPrincipal As New WindowsPrincipal(MyIdentity) 'Principal values. Dim PrincipalName As String = MyPrincipal.Identity.Name Dim PrincipalType As String = MyPrincipal.Identity.AuthenticationType Dim PrincipalAuth As String = MyPrincipal.Identity.IsAuthenticated.ToString() 'Identity values. Dim IdentName As String = MyIdentity.Name Dim IdentType As String = MyIdentity.AuthenticationType Dim IdentIsAuth As String = MyIdentity.IsAuthenticated.ToString() Dim ISAnon As String = MyIdentity.IsAnonymous.ToString() Dim IsG As String = MyIdentity.IsGuest.ToString() Dim IsSys As String = MyIdentity.IsSystem.ToString() Dim Token As String = MyIdentity.Token.ToString() Regards Ernesto
How is it possible ...
Edanmo Shell Extension: How to Install it? Getting Color Depth / Quality of display adpater / screen Transparent splash screen Carriage Return and Line Feed Syntax Treeview, Transparent Label Property of List of Classes TripleDES class - Suggestions Requested. Is it possible to have different columns of a datagrid bound to different datatables? |
|||||||||||||||||||||||