欢迎光临 Enjoy IT (ITECN.NET) 登录 | 注册 | 帮助

联合

公告

注意:本人的所有文档均可以引用,但引用必须说明出处。
修改后的枚举域内所有用户和计算机的脚本

前面一个博克帖子是简单的一个枚举操作,其缺点就是前面的说的。

修改后的脚本目的:
   1。域名不再采用绝对域名,而采用自动感知
   2。输出到一个文本文件,使得大量计算机和用户的输出不受限制
现在的脚本具有了更高的通用性。

呵呵!梦龙!你当我不知道你是谁啊?锵锵锵...我手持钢鞭将你打

 枚举用户并输出到文件

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("LDAP://rootDSE")
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("LDAP://rootDSE")
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

 

 

已发表 2007年10月12日 21:51 作者 qiqinghua

归档在:

评论

尚无任何评论

禁止匿名发表评论