Create a new module, and save it as "modGetPCName". Paste the following code into the new module:
Private Declare Function fPCName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fMachineName() As String
Dim lLength As Long, lngX As Long
Dim strPCName As String
lLength = 16
strPCName = String$(lLength, 0)
lvalue = fPCName(strPCName, lLength)
If lvalue <> 0 Then
fMachineName = Left$(strPCName, lLength)
Else
fMachineName = "<< No Name Found !!! >>"
End If
End Function
To use this function, you simply call it from just about anywhere within your application. Here is an example of the usage: Dim strPCName as String
strPCName = fMachineName
MsgBox "Your pc is named " & strPCName
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.