Chinaunix首页 | 论坛 | 博客
  • 博客访问: 408088
  • 博文数量: 87
  • 博客积分: 6015
  • 博客等级: 准将
  • 技术积分: 960
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-13 16:59
文章分类
文章存档

2015年(4)

2010年(16)

2009年(13)

2008年(12)

2007年(29)

2006年(13)

我的朋友

分类: WINDOWS

2010-03-18 09:13:07

枚举域内所有用户

dim i
Set con = CreateObject("ADODB.Connection")
Set com = CreateObject("ADODB.Command")
'Open the connection with the ADSI-OLEDB provider name
con.Provider = "ADsDSOObject"
con.Open
set objfso = createobject("scripting.filesystemobject")
set objfile = objfso.createtextfile("c:\adusers.txt")
Set objRootDSE = GetObject("")
strADsPath = "LDAP://" & objRootDSE.Get("defaultNamingContext")
Set objDomain = GetObject(strADsPath)
Com.ActiveConnection = con

Com.CommandText = "<"& stradspath &">;" & "(objectClass=user);SamAccountName;subTree"
wscript.echo " Your domain is " & stradspath
Set rs = Com.Execute()
i=0
Do Until rs.EOF
 if right(rs.Fields("samAccountName"),1)<>"$" then
   sResultText = sResultText & rs.Fields("SamAccountName") & ","& vbCrLf
   i=i+1
 end if
 rs.movenext
 
Loop
WScript.Echo sResultText
objfile.writeline sresulttext
objfile.writeline (" there are ") &i& (" users in your domain")
wscript.echo "There are "&i&" users in your domain"
wscript.echo "the output result write to c:\adusers.txt"

con.close

 

枚举计算机到文件

dim i
Set con = CreateObject("ADODB.Connection")
Set com = CreateObject("ADODB.Command")
'Open the connection with the ADSI-OLEDB provider name
con.Provider = "ADsDSOObject"
con.Open
set objfso = createobject("scripting.filesystemobject")
set objfile = objfso.createtextfile("c:\acomputers.txt")
Set objRootDSE = GetObject("")
strADsPath = "LDAP://" & objRootDSE.Get("defaultNamingContext")
Set objDomain = GetObject(strADsPath)
Com.ActiveConnection = con

Com.CommandText = "<"& stradspath &">;" & "(objectClass=computer);SamAccountName;subTree"
wscript.echo " Your domain is " & stradspath
Set rs = Com.Execute()
i=0
Do Until rs.EOF
sResultText = sResultText & rs.Fields("SamAccountName") & ","& vbCrLf
rs.MoveNext
i=i+1
Loop
WScript.Echo sResultText
objfile.writeline sresulttext
objfile.writeline (" there are ") &i& (" computers in your domain")
wscript.echo "There are "&i&" computers in your domain"
wscript.echo "the output result write to c:\acomputers.txt"

con.close

 

阅读(870) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~