VB更改PC的域名

时间:2014-06-14 15:55:40

标签: vb.net visual-studio-2010 visual-studio vbscript vb6

我想知道是否有办法通过使用Visual Basic或VB Script更改计算机上的域。我必须将100多台PC转移到另一个域。通过运行自动更改计算机上的域的应用程序将非常有用。

1 个答案:

答案 0 :(得分:3)

您可以使用Win32_ComputerSystem WMI类,例如在VBScript中:

Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2

domain   = "DOMAIN"
username = "user"
password = "pass"
ou       = Null  'create the computer object in the default location

Set net = CreateObject("WScript.Network")
Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!" _
          & "//./root/cimv2")

Set computer = wmi.Get("Win32_ComputerSystem.Name='" & net.ComputerName & "'")
result = computer.JoinDomainOrWorkgroup(domain, password, _
         domain & "\" & username, ou, JOIN_DOMAIN + ACCT_CREATE)
If result <> 0 Then
  WScript.Echo "Domain join failed (" & result & ")."
  WScript.Quit result
End If

For Each computer In wmi.ExecQuery("SELECT * FROM Win32_OperatingSystem")
  computer.Reboot
Next

或者你可以使用netdom命令:

netdom join %COMPUTERNAME% /domain:DOMAIN /userd:DOMAIN\USER /passwordd:PASS
shutdown -r -t 0