手机
当前位置:查字典教程网 >脚本专栏 >vbs >利用VBS脚本自动创建计算机帐户的代码
利用VBS脚本自动创建计算机帐户的代码
摘要:mcse注:其实这是按照ADSI(ActiveDirectoryServicesInterface:活动目录服务接口)写的程序。如果你安装了...

mcse注:其实这是按照ADSI(ActiveDirectoryServicesInterface:活动目录服务接口)写的程序。如果你安装了resourcekit,这段代码可以用netcom这条命令进行工作,下面是netcom的一个例子:

NETDOM/Domain:MYDOMAIN/user:adminuser/password:apasswordMEMBERMYCOMPUTER/ADD

复制代码 代码如下:

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

'*StartScript

'***********************

DimsComputerName,sUserOrGroup,sPath,computerContainer,rootDSE,lFlag

DimsecDescriptor,dACL,ACE,oComputer,sPwd

'

'*Declareconstantsusedindefiningthedefaultlocationforthe

'*machineaccount,flagstoidentifytheobjectasamachineaccount,

'*andsecurityflags

'ConstUF_WORKSTATION_TRUST_ACCOUNT=&H1000

ConstUF_ACCOUNTDISABLE=&H2

ConstUF_PASSWD_NOTREQD=&H20

ConstADS_GUID_COMPUTRS_CONTAINER="aa312825768811d1aded00c04fd8d5cd"

ConstADS_ACETYPE_ACCESS_ALLOWED=0

ConstADS_ACEFLAG_INHERIT_ACE=2

'

'*Settheflagsonthisobjecttoidentifyitasamachineaccount

'*anddeterminethename.Thenameisusedstaticallyhere,butmay

'*bedeterminedbyacommandlineparameterorbyusinganInputBox

'lFlag=UF_WORKSTATION_TRUST_ACCOUNTOrUF_ACCOUNTDISABLEOrUF_PASSWD_NOTREQD

sComputerName="TestAccount"

'

'*EstablishapathtothecontainerintheActiveDirectorywhere

'*themachineaccountwillbecreated.Inthisexample,thiswill

'*automaticallylocateadomaincontrollerforthedomain,readthe

'*domainname,andbindtothedefault"Computers"container

'*********************************************************************

SetrootDSE=GetObject("LDAP://RootDSE")

sPath="LDAP://SetcomputerContainer=GetObject(sPath)

sPath="LDAP://"&computerContainer.Get("distinguishedName")

SetcomputerContainer=GetObject(sPath)

''*Here,thecomputeraccountiscreated.Certainattributesmust

'*haveavaluebeforecalling.SetInfotocommit(write)theobject

'*totheActiveDirectory

'SetoComputer=computerContainer.Create("computer","CN="&sComputerName)

oComputer.Put"samAccountName",sComputerName+"$"

oComputer.Put"userAccountControl",lFlag

oComputer.SetInfo

'

'*Establishadefaultpasswordforthemachineaccount

'sPwd=sComputerName&"$"

sPwd=LCase(sPwd)

oComputer.SetPasswordsPwd

''*Specifywhichuserorgroupmayactivate/jointhiscomputertothe

'*domain.Inthisexample,"MYDOMAIN"isthedomainnameand

'*"JoeSmith"istheaccountbeinggiventhepermission.Notethat

'*thisisthedownlevelnamingconventionusedinthisexample.

'sUserOrGroup="MYDOMAINjoesmith"

''*BindtotheDiscretionaryACLonthenewlycreatedcomputeraccount

'*andcreateanAccessControlEntry(ACE)thatgivesthespecified

'*userorgroupfullcontrolonthemachineaccount

'SetsecDescriptor=oComputer.Get("ntSecurityDescriptor")

SetdACL=secDescriptor.DiscretionaryAcl

SetACE=CreateObject("AccessControlEntry")

'

'*AnAccessMaskof"-1"grantsFullControl

'

ACE.AccessMask=-1

ACE.AceType=ADS_ACETYPE_ACCESS_ALLOWED

ACE.AceFlags=ADS_ACEFLAG_INHERIT_ACE

''*Grantthiscontroltotheuserorgroupspecifiedearlier.

'ACE.Trustee=sUserOrGroup

'

'*Now,addthisACEtotheDACLonthemachineaccount

'dACL.AddAceACE

secDescriptor.DiscretionaryAcl=dACL

'

'*Commit(write)thesecuritychangestothemachineaccount

'oComputer.Put"ntSecurityDescriptor",Array(secDescriptor)

oComputer.SetInfo

''*Onceallparametersandpermissionshavebeenset,enablethe

'*account.

'

oComputer.AccountDisabled=False

oComputer.SetInfo

''*CreateanAccessControlEntry(ACE)thatgivesthespecifieduser

'*orgroupfullcontrolonthemachineaccount

'wscript.echo"Thecommandcompletedsuccessfully."

'*****************

'*EndScript

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

用vbs实现判断计算机是笔记本还是台式机的代码

用VBS记录客户机操作的代码

使用脚本自动修改ip设置

域内计算机和用户获取实现vbs代码

利用vbs脚本实现设置IE的打印页眉页脚信息

VBS 添加右键计算文件MD5的实现代码

用VBS修改远程桌面3389端口并添加到Windows防火墙的代码

初窥WMI_Vbs脚本编程简明教程补充读物第1/2页

VBS 脚本不能运行 提示Windows无法访问指定设备路径或文件

vbs复制文件夹的实现代码

精品推荐
分类导航