| :: How to Obtain the name of the computer... |
Author |
Andrea Tincani |
Language |
VB5, VB6 |
Operating
Systems |
Windows 95, 98 and NT |
| API
Declarations |
Private Declare Function GetComputerName Lib "kernel32.dll"
Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long |
| Module |
Public Function ComputerName() As String
Dim cn As String
Dim ls As Long
Dim res As Long
cn = String(1024, 0)
ls = 1024
res = GetComputerName(cn, ls)
If res <> 0 Then
ComputerName = Mid(cn, 1, InStr(cn, Chr(0)) -
1)
Else
ComputerName = ""
End If
End Function |
| Usage |
Private Sub Command1_Click()
MsgBox ComputerName
End Sub |
|
 |
|
 |