Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the username of local computer?

Status
Not open for further replies.

BigRedTexas

Programmer
Mar 14, 2002
22
0
0
US
I'm trying to append my username I'm logged on to my computer as onto a build version. How can I retrieve that via VB.NET?

Thanks, Scott
 
I'm not sure if .NET exposes this API call in a namespace so here's the delaration:

Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Sub Main()
Dim lLong As Long
Dim lLong2 As Long
lLong = 255
sCurrentUser = Space(lLong)
lLong2 = GetUserName(sCurrentUser, lLong)
sCurrentUser = RTrim(sCurrentUser)
end sub
 
This is not exaclty what you want, but to get the machine name you use:

Dim sMachName As String = Environment.MachineName.ToString

Kris
[pc2]
 
Try
dim username as string

username = security.Principal.WindowsIdentity.GetCurrent.Name

with Imports System.Security
 
This will give you the name without the domain

MyUserName=System.Windows.Forms.SystemInformation.UserName
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top