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

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

时间: 2024-09-14 11:05:42

利用VBS脚本自动创建计算机帐户的代码_vbs的相关文章

使用vbs脚本添加程序到自启动项的代码_vbs

因编辑器过滤了一些字符,比如&,所以下面的脚本可能会运行错误..看官添加&&这个字符就可以了. vbs脚本的功能呢是很多的,不过有时候我们只需要其中的某些功能,今天我突然想研究下怎么用vbs脚本实现添加程序到自启动项...... 首先来一段吧... 复制代码 代码如下: '========================================================================== ' ' VBScript Source File -- Cre

用VBS脚本实现更换Windows Xp序列号的代码_vbs

ON ERROR RESUME NEXT Dim VOL_PROD_KEY if Wscript.arguments.count<1 then VOL_PROD_KEY =InputBox("使用说明:"&vbCr&vbCr&"   本程序将自动替换你当前 Windows 的序列号,通过微软验证完全正版."&vbCr&vbCr&"序列号(OEM版无效,默认版本为 XP VLK):"& 

利用VBS脚本修改联想笔记本BIOS密码的代码分享

这篇文章主要介绍了利用VBS脚本修改联想笔记本BIOS密码的实现代码,感觉这不科学!无意中找到的一些资料,喜欢的朋友可以试试   这不科学!无意中找到的一些资料: vbs 代码: 复制代码 代码如下: strComputer = "." Set objWMIService = GetObject("winmgmts:" & strComputer & "rootWMI") ' Obtain an instance of the t

通过ASP.net程序创建域帐户故障

asp.net|程序|创建 我曾经成功地使用windows程序成功的创建了一批带邮箱的域帐户,但是,当我把这段代码交给我的一个同事(她负责开发Web应用)迁移到asp.net中后,只能创建域帐户,不能创建邮箱.为什么呢? 我们咨询了微软的工程师,他告诉我们,这是由于asp.net的权限不够,我们应该在asp.net模拟用户,这样就可以成功创建. 我将微软的相关文章摘录下来: 模拟 IIS 验证的帐户或用户 若要在收到 ASP.NET 应用程序中每个页的每个请求时模拟 Microsoft Inte

Win8系统创建用户帐户的方法

Windows8系统在创建用户帐户时,你能够创建两种类型的帐户:电脑的本地帐户或可在你使用的所有 Windows 8 和 Windows RT 电脑上使用的 Microsoft 帐户. 我们建议创建 Microsoft 帐户. 如果你的电脑在域中,则你创建的用户帐户可以授予人们访问你的电脑的权限,但无法授予其访问域的权限. 只有系统管理员才能创建域用户帐户. 创建 Microsoft 帐户的步骤 Microsoft 帐户是你用于登录到 Windows 的电子邮件地址和密码. 你可以使用任何电子邮

windows-禁止外接软件启动或改动计算机帐户

问题描述 禁止外接软件启动或改动计算机帐户 windows操作系统如何禁止外接软件启动或改动计算机帐户!!! 解决方案 新建一个用户,设为最普通的Users用户组.用该用户登录后运行软件.

跪求 自动投票程序 帐户限制的

问题描述 跪求自动投票程序帐户限制的最近朋友让我帮忙投票,我想如果有自动投票程序就好了,但是找了好多,都是简单的投票好用,遇到这样的就不知道怎么办了.朋友的比赛到月底就结束了,不知道是否有高手能帮我一下,做个自动投票程序!下面是投票地址:http://photo.sina.com.cn/ijoin/photo.php?pic_id=5048df8e2ae1bd60ce174补充:需要登录后才能投票,而且一个账户只能投一票! 解决方案 解决方案二:路过帮顶=============11月6日,论坛

调用基于JSON的EST API来创建一个帐户

WebSphere Cast Iron(以下简称 Cast Iron)被广泛用于整个内部和外部应用程序的集成和迁移.过去,大多数基于 SaaS 的应用程序都公开了 REST API,这些 API 用于处理 JSON 数据.然而,Cast Iron 主要处理 XML 和 XML 模式.为了支持有效的 REST API 调用,Cast Iron 引入了两个新活动来处理 JSON 数据. 您可以在调用 REST API (大部分是 SaaS 供应商公开的)的过程中使用 Read JSON 和 Writ

Win8如何创建用户帐户?(680Z5E系列)

1. 在桌面模式下,按键盘的[WIN]+[X]组合键打开高级管理工具,选择[控制面板].     2. 在控制面板中,选择[用户帐户和家庭安全].    3. 选择[用户帐户].    4. 点击下方的[管理其他帐户].   5. 选择[在电脑设置中添加新用户].    6. 找到"其他用户"下方的[添加用户]并点击进入.   7. 根据提示将"用户名"."密码"."重新输入密码"以及"密码提示"输入后,点