Re: Join Workgroup from command line
From: Andrew Mitchell (amitchel_at_removecasey.vic.gov.au)
Date: 03/18/04
- Next message: Andrew Mitchell: "Re: How can I disable network (type 3) Logon"
- Previous message: Karl Levinson [x y] mvp: "** READ THIS BEFORE POSTING - answers to frequently asked questions 2004.03.18"
- In reply to: Lefteris: "Join Workgroup from command line"
- Next in thread: Lefteris: "Re: Join Workgroup from command line"
- Reply: Lefteris: "Re: Join Workgroup from command line"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Thu, 18 Mar 2004 04:41:09 -0800
"=?Utf-8?B?TGVmdGVyaXM=?=" <anonymous@discussions.microsoft.com> 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
- Next message: Andrew Mitchell: "Re: How can I disable network (type 3) Logon"
- Previous message: Karl Levinson [x y] mvp: "** READ THIS BEFORE POSTING - answers to frequently asked questions 2004.03.18"
- In reply to: Lefteris: "Join Workgroup from command line"
- Next in thread: Lefteris: "Re: Join Workgroup from command line"
- Reply: Lefteris: "Re: Join Workgroup from command line"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|
|