让客户端加入域的脚本

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

把如下代码存成joinDomain.vbs, 然后双击运行它.

解释: 建立一个域用户帐号. 然后把DomainNameHere, PasswordHere, DomainAccountHere改成你的域名, 域用户密码, 域用户名. 在默认情况下, 普通域用户帐号只能加电脑到域十次, 而域管理员则不受限制. 如下代码我在XP下用域管理员帐号调试成功.


Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
strDomain = "DomainNameHere"
strPassword = "PasswordHere"
strUser = "DomainAccountHere"
Set objNetwork = CreateObject("work")
strComputer = puterName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2:Win32_='" & strComputer & "'") ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "\" & strUser, NULL, JOIN_DOMAIN + ACCT_CREATE) wscript.echo strComputer & " has been joined to domain:" & strDomain & ". You will neet to restart your PC to take effect."


要指出的是电脑未加入域时, 你是无法用域的组策略来使其运行脚本.













域环境内有大量客户机需要加入域的时候,一台一台的通过更改电脑属性那种方式加入域,是很麻烦的。这里提供一段加入域的代码只要在客户机运行,就可以加入域了,虽然还要一台台运行,但是一定程度上提高了工作效率。ps:双击运行后,并不会像以前那种方式加入域后提示重启。而是需要手动重启后,方可看到效果。

代码如下:

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
strDomain = "XXX" 注:这里添的是域名,可谓netbios或者域名
strPassword = "XXX" 注:这里添的是具有加入域权限的帐户的密码
strUser = "XXX" 注:这里添的是具有加入域权限的帐户
Set objNetwork = CreateObject("work")
strComputer = puterName
Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_='" & _
strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, _
strDomain & "\" & strUser, _
NULL, _
JOIN_DOMAIN + ACCT_CREATE)

wscript.echo "计算机加入域完成!按确定后重新启动电脑!"
set

ws=wscript.createobject("wscript.shell")
ws.run "shutdown
-r -t 0",0









有一个命令行 netdom (在support tools包)可以实现您的功能:& Q; N( C9 v8 P

/ S9 ]9 Z2 q, Y( c, e2 uNetdom join PC1 /domain:Company /reboot:30
* W/ F, k* R) J! i9 q' o& g1 b! h) L# ?% \& X
上面命令,加入PC1到company 域,30秒后重新启动计算机
" S5 B7 {" g) t! k! r
& g6 l- g3 x" T4 {- u& w" r, Z( G参数选项: W$ Y# e7 G7 x0 M/ W) J! L* q
X5 ~% W [5 i1 u0 b- B( p
/domain:name Required. Specifies the domain to join.9 i; E9 W; i2 g2 X0 f; f+ _
9 D1 z2 H# K+ s2 b$ G/ M% g. }
/ou:path Optional. Specifies the OU in which to create the computer account. If left out, the computer will be created in the default container.
; G, h" D Q( M" o# r( A* `# T/UserD:name /PasswordD:* Optional. Specifies an alternate account to be used to connect to the domain. Specify /PasswordD:* to be prompted for a password.0 J' C) L; t* j& ~
/UserO:name /PasswordO:* Optional. Specifies an alternate account for connecting to the targeted computer. Specify /PasswordO:* to be prompted for a password.
6 t0 G3 x+ ?4 z) w2 N7 j, y' U) @/reboot:seconds Optional. Specifies the number of seconds to wait before restarting the computer automatically. If omitted, the default is 20 seconds.
6 ]: F0 u* Z. O3 k" |# ~1 x
+ L/ n E( J e/ D9 Z) t

相关文档
最新文档