473,498 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11103
"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
4496
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
3934
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
670
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
2104
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
3073
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
334
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
3384
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
4051
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
3162
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
7126
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
7005
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
7210
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...
1
6891
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...
0
7381
tracyyun
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...
0
5465
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,...
0
4595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
293
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...

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.