欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-08-27 17:00:53
显示当前域内所有计算机名称及数目 复制代码 代码如下: const ads_scope_subtree = 2 set objrootdse = getobject("ld...
显示当前域内所有计算机名称及数目

复制代码 代码如下:

const ads_scope_subtree = 2
set objrootdse = getobject("ldap://rootdse")
strdomain = objrootdse.get("defaultnamingcontext")
set objconnection = createobject("adodb.connection")
set objcommand = createobject("adodb.command")
objconnection.provider = "adsdsoobject"
objconnection.open "active directory provider"
set objcommand.activeconnection = objconnection
objcommand.properties("page size") = 1000
objcommand.properties("searchscope") = ads_scope_subtree
objcommand.commandtext = "select * from 'ldap://" & strdomain & "' where objectcategory='computer'"
set objrecordset = objcommand.execute
objrecordset.movefirst
do until objrecordset.eof
wscript.echo objrecordset.fields("adspath").value
objrecordset.movenext
loop
wscript.echo ""
wscript.echo "total computer: "&objrecordset.recordcount

显示当前域内所有用户名称及数目
复制代码 代码如下:

const ads_scope_subtree = 2
set objrootdse = getobject("ldap://rootdse")
strdomain = objrootdse.get("defaultnamingcontext")
set objconnection = createobject("adodb.connection")
set objcommand = createobject("adodb.command")
objconnection.provider = "adsdsoobject"
objconnection.open "active directory provider"
set objcommand.activeconnection = objconnection
objcommand.properties("page size") = 1000
objcommand.properties("searchscope") = ads_scope_subtree
objcommand.commandtext = "select * from 'ldap://" & strdomain & "' where objectcategory='user'"
set objrecordset = objcommand.execute
objrecordset.movefirst
do until objrecordset.eof
wscript.echo objrecordset.fields("adspath").value
objrecordset.movenext
loop
wscript.echo ""
wscript.echo "total user: "&objrecordset.recordcount