利用VBS脚本自动创建计算机帐户的代码

所属分类: 脚本专栏 / vbs 阅读数: 2001
收藏 0 赞 0 分享
mcse注:其实这是 按照ADSI(Active Directory Services Interface:活动目录服务接口)写的程序。如果你安装了resource kit,这段代码可以用netcom这条命令进行工作,下面是netcom的一个例子: 

  NETDOM /Domain:MYDOMAIN /user:adminuser /password:apassword MEMBER MYCOMPUTER /ADD 

复制代码 代码如下:

  ***********************

  '* 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 UF_PASSWD_NOTREQD = &H20

  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 Or UF_PASSWD_NOTREQD

  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://  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


更多精彩内容其他人还在看

用vbscript来添加ip策略 自动封IP

看过有网友介绍的方法,不过是手工一条一条地封,而攻击IP一般都是数千个不同的IP。用手工封IP的办法太麻烦。下面我们用程序来实现自动封这些IP!
收藏 0 赞 0 分享

vbs,hta中选择文件夹对话框实现代码

在vbs中选择文件夹可以直接调用系统的文件夹对话框
收藏 0 赞 0 分享

WMI 脚本高手不完全手册

要成为WMI脚本高手当要认识一下什么叫WMI啦,下面将介绍一下有关WMI的东西。
收藏 0 赞 0 分享

vbscript语句中“&H”专用于16进制数表示

近段时间在做一个asp的项目,由于数据库里面的字段采用字母“h”开头,在sql语言时就出现了莫名其妙的错误,经过反复的检查,也没查出有错误的地方,整整给折腾了我一天的时间。
收藏 0 赞 0 分享

URL 筛选小工具 提取网页中的超链接地址

这个VBS是用来将一个本地网页中的URL筛选出来并保存在新的网页文件中。当然,只要改变里面的正则表达式,就可以作其他用途了。
收藏 0 赞 0 分享

VBScript 文件操作代码小结

下面是一些vbs下常用到的一些文件操作代码,整理了下方便以后开发使用,提高效率。
收藏 0 赞 0 分享

vbs 错误捕获器,用于捕获内部错误并进行手工处理

vbs中的错误捕获器,用于捕获内部错误并进行手工处理
收藏 0 赞 0 分享

查看SQL状态的vbs(检验SQL SERVER是否在这机器上工作 )

这篇文章主要介绍了查看SQL状态的vbs,主要检验SQL SERVER是否在这机器上工作,需要的朋友可以参考下
收藏 0 赞 0 分享

vbs 字符统计功能模块

TongJi()将上面代码保存为TongJi.vbs,在TongJi.vbs同目录下建立ok.txt文本文件,将你要统计的文本复制到ok.txt中,运行TongJi.vbs即可以统计字数,与word的功能一样。
收藏 0 赞 0 分享

重新安装ie的一个vbs

对于版本有点老,所以建议学习使用,不要随便直接运行。
收藏 0 赞 0 分享
查看更多