热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

mcse注:其实这是 按照adsi(active directory services interface:活动目录服务接口)写的程序。如果你安装了resource kit,这段代

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



推荐阅读
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • Java太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • 本文介绍了UVALive6575题目Odd and Even Zeroes的解法,使用了数位dp和找规律的方法。阶乘的定义和性质被介绍,并给出了一些例子。其中,部分阶乘的尾零个数为奇数,部分为偶数。 ... [详细]
  • 本文介绍了南邮ctf-web的writeup,包括签到题和md5 collision。在CTF比赛和渗透测试中,可以通过查看源代码、代码注释、页面隐藏元素、超链接和HTTP响应头部来寻找flag或提示信息。利用PHP弱类型,可以发现md5('QNKCDZO')='0e830400451993494058024219903391'和md5('240610708')='0e462097431906509019562988736854'。 ... [详细]
  • 本文介绍了一个题目的解法,通过二分答案来解决问题,但困难在于如何进行检查。文章提供了一种逃逸方式,通过移动最慢的宿管来锁门时跑到更居中的位置,从而使所有合格的寝室都居中。文章还提到可以分开判断两边的情况,并使用前缀和的方式来求出在任意时刻能够到达宿管即将锁门的寝室的人数。最后,文章提到可以改成O(n)的直接枚举来解决问题。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • 预备知识可参考我整理的博客Windows编程之线程:https:www.cnblogs.comZhuSenlinp16662075.htmlWindows编程之线程同步:https ... [详细]
  • Java自带的观察者模式及实现方法详解
    本文介绍了Java自带的观察者模式,包括Observer和Observable对象的定义和使用方法。通过添加观察者和设置内部标志位,当被观察者中的事件发生变化时,通知观察者对象并执行相应的操作。实现观察者模式非常简单,只需继承Observable类和实现Observer接口即可。详情请参考Java官方api文档。 ... [详细]
  • JDK源码学习之HashTable(附带面试题)的学习笔记
    本文介绍了JDK源码学习之HashTable(附带面试题)的学习笔记,包括HashTable的定义、数据类型、与HashMap的关系和区别。文章提供了干货,并附带了其他相关主题的学习笔记。 ... [详细]
author-avatar
天极玩家_136
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有