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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do get the Network Username & Computer Name?

Status
Not open for further replies.

bob000

Programmer
Aug 23, 2001
20
US
How do I get the Network Username (Microsoft Network) and/or the Computer Name returned for use in Access 2000?
 
Try this:
Code:
Option Compare Database
Option Explicit

    Public Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long         'i.e. strUserNetworkName = MMC_WNetGetUser "", strUser, 255
    Public Declare Function GetComputerName Lib "kernel32.dll" Alias "GetComputerNameA" (ByVal buffer As String, ByRef nsize As Long) As Boolean

Function GetUserNameComputerName()

    Const MAXCHAR As Integer = 50           'Max. no. of chars. in computer name
    
    Dim strHost As String                   'Name of computer returned by function
    Dim strUserName As String               'Network Name of User

'*****************************
'*  Get User's Network Name  *
'*****************************

    strUserName = Space(255)
    WNetGetUser "", strUserName, 255
    Debug.Print Trim(strUserName)
   
'******************************
'*  Get User's Computer Name  *
'******************************

    strHost = String(MAXCHAR, 0)
    GetComputerName strHost, MAXCHAR
    Debug.Print Trim(strHost)

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top