首页 > 编程 > VBScript > 正文

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

2020-06-26 18:24:04
字体:
来源:转载
供稿:网友
域内计算机和用户获取(转自冰点极限-赤龙),学习vbs的朋友可以参考下。
 
显示当前域内所有计算机名称及数目 

复制代码代码如下:

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 
 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表