Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Get computer name


Private Declare Function GetComputerName Lib "kernel32.dll <API_KERNEL32.html>" 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