=?Utf-8?B?TGVmdGVyaXM=?= said:
Hi,
Is there a way to join a windows 2000 pro computer to a workgroup from
command line or vbscript? Any help is greatly appreciated.
Lefteris
Try this as a .vbs file. (watch for line wrapping)
Andy.
'Adds a computer to a Workgroup or Domain then reboots.
'Set the strDomain, strUser and strPassword to suit your environment
Option Explicit
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
Dim strDomain, strPassword, strUser, strComputer, ReturnValue
Dim objComputer, objNetwork, objWMIService, objOperatingSystem
Dim colOperatingSystems
'Domain or workgroup name
strDomain = "Domain_Or_Workgroup_Name"
'Account details with access to add computers to domain or workgroup
strUser = "Account"
strPassword = "Password"
'Add the computer to the domain/workgroup
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!
\\" & _
strComputer & "\root\cimv2:Win32
_ComputerSystem.Name='" & _
strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, _
strDomain & "\" &
strUser, _
NULL, _
JOIN_DOMAIN +
ACCT_CREATE)
'Display Completion Message to user
Dim objShell, intValue
Set objShell = CreateObject("WScript.Shell")
intValue = objShell.Popup("Your computer has been added to the ' &
strDomain & ' Domain." _
& vbCRLF & "Your computer will now reboot.", , , vbExclamation
+ vbOKOnly)
'Reboot PC
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer &
"\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()
Next