创建计算机帐户使用"NETDOM
请注意您应使用仅在 Windows XP 版本
netdom ,附带 Windows XP CD Support\Tools\Support.cab 文件中。 以前的版本用于 Windows XP 中的所有功能无法正常工作。
您可以使用
netdom 命令行 (或从一个批处理文件 (可选) 调用该) 脚本的计算机创建帐户。 本示例将创建只有计算机帐户,并显示如何指定有权在域中创建计算机帐户的授权用户的凭据。 执行
netdom 命令的语法的以下示例
netdom 加入 ComputerName / domain: DomainName / userd: User / passwordd: UserPassword
其中,
User 是有权限加入该域的用户。
有关使用 NETDOM 的详细信息,单击下面的文章编号,以查看 Microsoft 知识库中的文章:
150493?
(http://support.microsoft.com/kb/150493/
)
如何从命令行加入域
脚本使用 ADSI 和 Windows Script Host,计算机帐户
通过使用 Active Directory 服务接口 (ADSI) 和 Windows Script Host (WSH),管理员可以创建一个 Visual Basic 脚本 (VBScript) 自动创建计算机帐户。
有关 Visual Basic 脚本的详细信息,请访问下面的 Microsoft Web 站点:
若要使用此方法,下面的示例脚本所示创建脚本,然后以.vbs 扩展名中保存文件。 若要运行该文件,请双击该文件,或在命令提示符处键入
cscript myscript.vbs 。
示例脚本
'***********************
'* Start Script
'***********************
Dim sComputerName, sUserOrGroup, sPath, computerContainer, rootDSE, lFlag
Dim secDescriptor, dACL, ACE, oComputer, sPwd
'*********************************************************************
'* Declare constants used in defining the default location for the
'* machine account, flags to identify the object as a machine account,
'* and security flags
'*********************************************************************
Const UF_WORKSTATION_TRUST_ACCOUNT = &H1000
Const UF_ACCOUNTDISABLE = &H2
Const ADS_GUID_COMPUTRS_CONTAINER = "aa312825768811d1aded00c04fd8d5cd"
Const ADS_ACETYPE_ACCESS_ALLOWED = 0
Const ADS_ACEFLAG_INHERIT_ACE = 2
'*********************************************************************
'* Set the flags on this object to identify it as a machine account
'* and determine the name. The name is used statically here, but may
'* be determined by a command line parameter or by using an InputBox
'*********************************************************************
lFlag = UF_WORKSTATION_TRUST_ACCOUNT Or UF_ACCOUNTDISABLE
sComputerName = "TestAccount"
'*********************************************************************
'* Establish a path to the container in the Active Directory where
'* the machine account will be created. In this example, this will
'* automatically locate a domain controller for the domain, read the
'* domain name, and bind to the default "Computers" container
'*********************************************************************
Set rootDSE = GetObject("LDAP://RootDSE")
sPath = "LDAP://<WKGUID=" & ADS_GUID_COMPUTRS_CONTAINER
sPath = sPath + ","
sPath = sPath + rootDSE.Get("defaultNamingContext")
sPath = sPath + ">"
Set computerContainer = GetObject(sPath)
sPath = "LDAP://" & computerContainer.Get("distinguishedName")
Set computerContainer = GetObject(sPath)
'*********************************************************************
'* Here, the computer account is created. Certain attributes must
'* have a value before calling .SetInfo to commit (write) the object
'* to the Active Directory
'*********************************************************************
Set oComputer = computerContainer.Create("computer", "CN=" & sComputerName)
oComputer.Put "samAccountName", sComputerName + "$"
oComputer.Put "userAccountControl", lFlag
oComputer.SetInfo
'*********************************************************************
'* Establish a default password for the machine account
'*********************************************************************
sPwd = sComputerName & "$"
sPwd = LCase(sPwd)
oComputer.SetPassword sPwd
'*********************************************************************
'* Specify which user or group may activate/join this computer to the
'* domain. In this example, "MYDOMAIN" is the domain name and
'* "JoeSmith" is the account being given the permission. Note that
'* this is the downlevel naming convention used in this example.
'*********************************************************************
sUserOrGroup = "MYDOMAIN\joesmith"
'*********************************************************************
'* Bind to the Discretionary ACL on the newly created computer account
'* and create an Access Control Entry (ACE) that gives the specified
'* user or group full control on the machine account
'*********************************************************************
Set secDescriptor = oComputer.Get("ntSecurityDescriptor")
Set dACL = secDescriptor.DiscretionaryAcl
Set ACE = CreateObject("AccessControlEntry")
'*********************************************************************
'* An AccessMask of "-1" grants Full Control
'*********************************************************************
ACE.AccessMask = -1
ACE.AceType = ADS_ACETYPE_ACCESS_ALLOWED
ACE.AceFlags = ADS_ACEFLAG_INHERIT_ACE
'*********************************************************************
'* Grant this control to the user or group specified earlier.
'*********************************************************************
ACE.Trustee = sUserOrGroup
'*********************************************************************
'* Now, add this ACE to the DACL on the machine account
'*********************************************************************
dACL.AddAce ACE
secDescriptor.DiscretionaryAcl = dACL
'*********************************************************************
'* Commit (write) the security changes to the machine account
'*********************************************************************
oComputer.Put "ntSecurityDescriptor", Array(secDescriptor)
oComputer.SetInfo
'*********************************************************************
'* Once all parameters and permissions have been set, enable the
'* account.
'*********************************************************************
oComputer.AccountDisabled = False
oComputer.SetInfo
'*********************************************************************
'* Create an Access Control Entry (ACE) that gives the specified user
'* or group full control on the machine account
'*********************************************************************
wscript.echo "The command completed successfully."
'*****************
'* End Script
'*****************Microsoft 提供仅,用于说明的编程示例不附带任何明示或默示的保证。 这包括,但不限于适销性或针对特定用途的适用性的默示保证。 本文假定您熟悉所演示的编程语言和用于创建和调试过程的该工具。 Microsoft 支持工程师可以帮助解释某个特定的过程的功能,但是它们不会修改这些示例以提供额外的功能或构建过程以满足您的特殊需求。
有关 UserAccountControl 标志的更多信息,单击下面的文章编号,以查看 Microsoft 知识库中的文章:
305144?
(http://support.microsoft.com/kb/305144/
)
如何使用 UserAccountControl 标志处理用户帐户属性