Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function ShowWindow Lib "USER32" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Function computerName() As String
Dim tmpstr As String
Dim l As Long
tmpstr = String(256, 0)
l = GetComputerName(tmpstr, 256)
computerName = Left$(tmpstr, InStr(tmpstr, Chr(0)) - 1)
cClientName = computerName
End Function
Private Declare Function SetComputerName Lib "kernel32" Alias "SetComputerNameA" (ByVal lpComputerName As String) As Long
Private Sub Form_Load()
Dim sNewName As String
'Ask for a new computer name
sNewName = InputBox("Please enter a new computer name.")
'Set the new computer name
SetComputerName sNewName
MsgBox "Computername set to " + sNewName
End Sub
声明:
Declare Function SetComputerName Lib "kernel32" Alias "SetComputerNameA" (ByVal lpComputerName As String) As Long
使用:
NewName = "Hello World"
SetComputerName NewName