How can I get the login name of the user currently logged into Windows as a
string?
Thanks,
Steve Enzer 13 39141
Hi Steve,
System.Environment.UserName
--
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
"Steve Enzer" <no****@nospam.com> escribió en el mensaje
news:e1**************@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]" <ca*****@NOSPAMsogecable.com> wrote in message news:Op**************@TK2MSFTNGP10.phx.gbl... Hi Steve,
System.Environment.UserName
How simple. Ive been using
System.Security.Principal.WindowsIdentity.GetCurre nt().Name
--
Al Reid --
Best regards,
Carlos J. Quintero
Hi,
Imports System.Security
Imports System.Security.Principal
AppDomain.CurrentDomain.SetPrincipalPolicy(Princip alPolicy.WindowsPrincipal)
Dim myID As WindowsIdentity = WindowsIdentity.GetCurrent()
Msgbox("The Current User is : " & myID.Name)
Regards,
Cerebrus.
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" <ar*****@reidDASHhome.com> escribió en el mensaje
news:Ov*************@TK2MSFTNGP12.phx.gbl... "Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> wrote in message news:Op**************@TK2MSFTNGP10.phx.gbl... Hi Steve,
System.Environment.UserName
How simple. Ive been using System.Security.Principal.WindowsIdentity.GetCurre nt().Name
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.
FYI, the My.User.Name functionality does not work for a console app.
"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> wrote in message
news:%2****************@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" <ar*****@reidDASHhome.com> escribió en el mensaje news:Ov*************@TK2MSFTNGP12.phx.gbl... "Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> wrote in message news:Op**************@TK2MSFTNGP10.phx.gbl... Hi Steve,
System.Environment.UserName
How simple. Ive been using System.Security.Principal.WindowsIdentity.GetCurre nt().Name
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
Thanks for all the suggestions!
Steve
The My namespace doesn't exist for console applications.
"Joe Sutphin" <jo********@earthlink.net> wrote in message
news:uZ*************@tk2msftngp13.phx.gbl... FYI, the My.User.Name functionality does not work for a console app.
"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> wrote in message news:%2****************@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" <ar*****@reidDASHhome.com> escribió en el mensaje news:Ov*************@TK2MSFTNGP12.phx.gbl... "Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> wrote in message news:Op**************@TK2MSFTNGP10.phx.gbl... Hi Steve,
System.Environment.UserName
How simple. Ive been using System.Security.Principal.WindowsIdentity.GetCurre nt().Name
"AMDRIT" <am****@hotmail.com> schrieb: The My namespace doesn't exist for console applications.
Well, with conditional compilation constants it's maybe possible to add it
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/>
Hi,
Yes, Environment.Username makes internally a call to the Win32 API function
GetUserName and according to the docs
( http://msdn.microsoft.com/library/de...etusername.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)...
--
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
"Cerebrus99" <zo*****@sify.com> escribió en el mensaje
news:11*********************@g43g2000cwa.googlegro ups.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.
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)
"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> wrote in message
news:%2****************@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" <ar*****@reidDASHhome.com> escribió en el mensaje news:Ov*************@TK2MSFTNGP12.phx.gbl... "Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> wrote in message news:Op**************@TK2MSFTNGP10.phx.gbl... Hi Steve,
System.Environment.UserName
How simple. Ive been using System.Security.Principal.WindowsIdentity.GetCurre nt().Name
No, duh !
"AMDRIT" <am****@hotmail.com> wrote in message
news:eP**************@TK2MSFTNGP12.phx.gbl... The My namespace doesn't exist for console applications.
"Joe Sutphin" <jo********@earthlink.net> wrote in message news:uZ*************@tk2msftngp13.phx.gbl... FYI, the My.User.Name functionality does not work for a console app.
"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> wrote in message news:%2****************@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" <ar*****@reidDASHhome.com> escribió en el mensaje news:Ov*************@TK2MSFTNGP12.phx.gbl... "Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> wrote in message news:Op**************@TK2MSFTNGP10.phx.gbl... > Hi Steve, > > System.Environment.UserName
How simple. Ive been using System.Security.Principal.WindowsIdentity.GetCurre nt().Name
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: pl |
last post by:
Hi all,
I followed the mails entitled 'How to turn a variable name into a
string?' in march 2005 posts as I have a similar problem.
I have to get some list variable names at some point in my...
|
by: Mike Turco |
last post by:
(This was also posted to comp.database.ms-access before I realized this was
the hep group.)
Lets say that my WinXP computer has two users: Michael and Kathryn. One or
the other logs into the...
|
by: Homauoon |
last post by:
Dear sir
I want to get current user name from system
(in windows applications) by using WNetGetUser
function from Mpr.lib.
Please help me.
Thanks
|
by: djbitchpimp |
last post by:
How do I retrieve the username of the currently logged in user? I
basically to check if the user is logged in as root and if not, exit
the program.
I though about using the LOGNAME environment...
|
by: Joe |
last post by:
This may actually be an IIS configuration issue but any help would be
appreciated.
I'd like to display some content based upon who the current user is that is
accessing an internal ASP.NET...
|
by: pukya78 |
last post by:
Hi,
I am trying to get the current file and the line number which is
getting executed. I used:
MessageBox.Show(New StackTrace(New
StackFrame(True)).GetFrame(0).GetFileLineNumber) which gives me...
|
by: John Q |
last post by:
In Silverlight Application it's possible to query current Application's
hostname and port using namespace Windows.System and code like
below. Iused it in WCF client call.
String hostname =...
|
by: =?Utf-8?B?SGVsZW4gVHJpbQ==?= |
last post by:
I have upgraded a Web application from Visual Studio 2003 to 2008. A line of
code that was working now returns an empty string:
UserName = System.Web.HttpContext.Current.User.Identity.Name
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
|
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...
| |