how i get computer name with vb 6?
any help will be appreciated
thanks :)

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

commented: thx +1

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.

commented: :) +1

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
commented: this is very Great Code. Works like charm :). thanks buddy +1
commented: help me too +1

thanks for the code all. its worked :)

you're welcome

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.