473,386 Members | 1,779 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,386 software developers and data experts.

GetUserName

I am using VB.NET and need to get the user's name that
has logged onto the user's computer. In VB6 I used an
API call. Is this still the most efficint way or does
the .NET framework have an easier, more efficint way of
getting the user's name?

Many Thanks,

Nov 20 '05 #1
4 11096
"Robert" <ro********@triad.rr.com> wrote in message
news:06****************************@phx.gbl...
I am using VB.NET and need to get the user's name that
has logged onto the user's computer.


Public Function GetUserName() As String
GetUserName = (SystemInformation.UserName.ToString)
' This will return only the user name
End Function
' If you want the domain name included, use the code:
Imports System
Imports System.Security
Public Module SysInfo
Public Function GetUserName() As String
Principal.WindowsIdentity.GetCurrent.Name
' This will return 'domain\username'
End Function
End Module

or

' You can also call the code direct, such as Text1.Text =
(SystemInformation.UserName.ToString)
Nov 20 '05 #2
Robert,
Is this still the most efficint way or does
the .NET framework have an easier, more efficint way of
getting the user's name?


System.Environment.UserName

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #3
* "Robert" <ro********@triad.rr.com> scripsit:
I am using VB.NET and need to get the user's name that
has logged onto the user's computer. In VB6 I used an
API call. Is this still the most efficint way or does
the .NET framework have an easier, more efficint way of
getting the user's name?


'Environment.UserName'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
On 2004-01-10, Robert <ro********@triad.rr.com> wrote:
I am using VB.NET and need to get the user's name that
has logged onto the user's computer. In VB6 I used an
API call. Is this still the most efficint way or does
the .NET framework have an easier, more efficint way of
getting the user's name?

Many Thanks,


System.Environment.UserName

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #5

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

Similar topics

1
by: smj92I | last post by:
Hello How to get the name of the user logged in the server side, is there something like GetUserName? Thanks
3
by: casey a | last post by:
Hi all, I would like to take the function below and write the user name to a field on a form and store it in the corresponding table but I'm not sure how to get to where I'm at to where I need to...
2
by: jack | last post by:
Hi everyone, In VB.NET, is getting the network username still the same as VB 6.0, i.e. using the the following API: Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA"...
1
by: Sandy | last post by:
HI All, I have created a MFC exe using VC++ .NET 2003 on Windows XP Prof service pack 2 and it works properly on my machine, but when I run the same exe on a different machine (Windows XP Prof...
4
by: Sandy | last post by:
HI All, I have created a MFC exe using VC++ .NET 2003 on Windows XP Prof service pack 2 and it works properly on my machine, but when I run the same exe on a different machine (Windows XP Prof...
0
by: Sandy | last post by:
HI All, I have created a MFC exe using VC++ .NET 2003 on Windows XP Prof service pack 2 and it works properly on my machine, but when I run the same exe on a different machine (Windows XP Prof...
5
by: jlbess | last post by:
I'm using the following code in a C++ dll to retrieve the windows username of the current logged in user. I'm passing the username to a case sensitive application so I need to convert it to all lower...
11
by: Ed Dror | last post by:
Hi there, I'm using ASP.NET 2.0 and SQL Server 2005 with VS 2005 Pro. I have a Price page (my website require login) with GridView with the following columns PriceID, Amount, Approved,...
5
by: venujune6 | last post by:
Hi, I have a tool which is made in C and uses the API GetUserName(). But we have the problem as the user says it gives incorrect username "sometimes". When the failure occurs, the username. that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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
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...
0
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
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...

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.