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 functions

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

Get the computer name

Define a new function to do the rest of the task. So you can reuse the code.

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

Just invoke the function and place values to a Text Box

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.