Private Declare Function GetComputerName Lib "kernel32.dll" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

'------------------------------
'it is also in the registry at
'HKLM \ System \ CurrentControlSet \ Control \ ComputerName \ ComputerName

'---------------------------
'Use the GetComputerName API Function .
Private Sub Form_Load()
Dim computer_name As String
Dim length As Long

   computer_name = Space$(256)
   length = Len(computer_name)
   GetComputerName computer_name, length
   computer_name = Left$(computer_name, length)

   lblComputerName.Caption = "[" & computer_name & "]"
End Sub

Requires a label named 'lblComputerName' to be on the form.

I found this here http://www.garybeene.com/code/visual%20basic250.htm

Comments
thx

go to Components then add Microsoft Winsock Control. then use the code below....

lblHost.Caption = "Hostname: " & sock1.LocalHostName
'where lblHost is a label, sock1 is a winsock control 
'you can also get the local Ip by .LocalIp property

hope this helps.

Comments
:)

use this following code :

Private Const MAX_COMPUTERNAME_LENGTH As Long = 31
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Sub GetCompName()
Dim dwLen As Long
    Dim strString As String
    'Create a buffer
    dwLen = MAX_COMPUTERNAME_LENGTH + 1
    strString = String(dwLen, "X")
    'Get the computer name
    GetComputerName strString, dwLen
    'get only the actual data
    strString = Left(strString, dwLen)
    'Show the computer name
    MsgBox "WELCOME " & strString
   
End Sub

Private Sub Form_Load()
GetCompName
End Sub
Comments
help me too
this is very Great Code. Works like charm :). thanks buddy
This question has already been answered. Start a new discussion instead.