Option ExplicitPrivate 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
Private Declare Function SetComputerName Lib "kernel32" Alias "SetComputerNameA" ( _ ByVal lpComputerName As String) As LongPrivate Sub Command1_Click() Dim res As Long res = SetComputerName("RT000588") '更名為:Rt000588 If res <> 0 Then MsgBox "成功更名" Else MsgBox "更名失敗" End If End Sub
Wmi可以这样 Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2") Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem") For Each objComputer in colComputers err = ObjComputer.Rename("陈唐晖")'机器名 ReturnValue = objComputer.JoinDomainOrWorkGroup("技术中心")'工作组 Next
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
Dim res As Long
res = SetComputerName("RT000588") '更名為:Rt000588
If res <> 0 Then
MsgBox "成功更名"
Else
MsgBox "更名失敗"
End If
End Sub
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
err = ObjComputer.Rename("陈唐晖")'机器名
ReturnValue = objComputer.JoinDomainOrWorkGroup("技术中心")'工作组
Next