' Win32API Examle - GetComputerName
'
' Jon Vote 02/2002
'
' 1) Create a new project. Form1 will be created by default.
' 2) Add a Command Button to the form.
' 3) Paste the following code into the declarations section of Form1:
' --- Begin code for Form1 ---
Option Explicit
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Form_Load()
Me.Caption = "Win32API Example - GetComputerName"
Command1.Width = 1680
Command1.Caption = "&GetComputerName"
Command1.Left = (Me.ScaleWidth - Command1.Width) / 2
End Sub
Private Sub Command1_Click()
Dim lngReturnCode As Long
Dim strBuffer As String
Dim lngSize As Long
strBuffer = Space$(80)
lngSize = Len(strBuffer)
lngReturnCode = GetComputerName(strBuffer, lngSize)
MsgBox "The name of this computer is: " & Trim$(strBuffer)
End Sub
' --- End code for Form1 ---