不想要通过控制面板--系统--....或者右键我的电脑--属性...这样子来更改

解决方案 »

  1.   

    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
      

  2.   

    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
      

  3.   

    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