All pastes #1629994 Raw Edit

Access: Get PC Name

public text v1 · immutable
#1629994 ·published 2009-10-19 15:29 UTC
rendered paste body
Private Declare Function GetComputerNameA Lib "kernel32" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function GetUserName Lib "ADVAPI32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function GetComputerName() As String
On Error GoTo Err_GetComputerName
Dim Username As String * 255
Call GetComputerNameA(Username, 255)
GetComputerName = Left$(Username, InStr(Username, Chr$(0)) - 1)

Exit_GetComputerName:
   Exit Function

Err_GetComputerName:
       MsgBox Err.Description
       Resume Exit_GetComputerName

End Function