How to get Computer Name using VB6 Code


Accessing system property is pretty easy with VB6 code. This can be useful when programmers need to refer the system name in the code.

Steps

  • Declare the GetComputerNameA function which resides in the kernel32 library
  • Create function to fetch the Computer Name.
  • Use the function

The Kernel function

 Declare Function GetComputerNameA Lib “kernel32” (ByVal lpBuffer As String, nSize As Long) As Long

Get the computer name

Public Function GetComputerName() As String
Dim sResult As String * 255
GetComputerNameA sResult, 255
GetComputerName = Left$(sResult, InStr(sResult, Chr$(0)) – 1)
End Function

Calling the function

Text1.Text = GetComputerName

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.