' Statement GetComputerName
Private Declare Function getcomputername Lib "kernel32" Alias "Getcomputernamea" (ByVal lpbuffer as String, nSize as Long) As Long
' Statement Setcomputername
Private Declare Function setcomputername Lib "kernel32" Alias "Setcomputernamea" (ByVal Lpcomputername as String) as Long
' Define a function to get the computer name
Private Function getcname (ByRef CName) as Boolean
Dim scname as String ' computer name
Dim Lcomputernamelen as Long ' computer name length
Dim LResult as Long ' GetComputerName return value
Dim RV as Boolean ' getcname return value, if TRUE indicates successful operation
Lcomputernamelen = 256
Scname = Space (Lcomputernamelen)
LResult = GetComputerName (Scname, Lcomputernamelen)
If LResult <> 0 Then
CName = left$ (Scname, Lcomputernamelen)
RV = True
Else
RV = False
End If
Getcname = RV
End Function
' Defines a function that modifies a computer's name
Private Function setcname (ByVal CName as String) as Boolean
Dim LResult as Long
Dim RV as Boolean
LResult = Setcomputername (CName)
If LResult <> 0 Then
RV = True ' modification succeeded
Else
RV = False
End If
Setcname = RV
End Function
Get Computer name