I want to be able to enter a username into a textbox and then click a command button and it tells me the machine name. How could I go about doing this?
Printable View
I want to be able to enter a username into a textbox and then click a command button and it tells me the machine name. How could I go about doing this?
^
Use this API to get the computer name.
Code:Option Explicit
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
Private Function ComputerName()
Dim strCompName As String
Dim strCN As String
strCompName = String(255, Chr$(0))
GetComputerName strCompName, 255
strCN = InStr(1, strCompName, Chr$(0))
strCompName = Left$(strCompName, strCN - 1)
ComputerName = strCompName
'OPTIONAL
MsgBox "This Computer's Name Is: " & strCompName, vbOkOnly + vbInformation
End Function