域内计算机和用户获取实现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
复制代码 代码如下:
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