一个MVP写的vb代码
const ADS_SCOPE_SUBTREE=2
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") = 200
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT adspath,name FROM 'LDAP://dc=shenma,dc=local' WHERE objectCategory='user' "
Set objRec = objCommand.Execute
if objRec.BOF OR objRec.EOF then
wscript.echo "不存在"
else
FOR i = 1 to objRec.RecordCount
UserPATH = objRec.Fields("adsPath").Value
set obj = GetObject(UserPATH)
obj.setpassword "111111"
obj.setinfo
wscript.echo objRec.Fields("name").Value
objRec.MoveNext
Next
wscript.echo objRec.RecordCount&"个用户成功!"
end if
-------------------------------------
需要点N次确定,很郁闷。
下面这个:
' Example VBScript to change a user's password
' ---------------------------------------------------------'
Option Explicit
Dim objOU,objUser,objRootDSE
Dim strContainer,strDNSDomain,strPassword
Dim intCounter,intAccValue,intPwdValue
' --------------------------------------------------------'
' Note: Please change OU=zjsystem,to reflect your domain
' --------------------------------------------------------'
strContainer = "OU=zjsystem,"
strPassword = "888888"
intAccValue = 544
intPwdValue = 0
intCounter = 0
' -------------------------------------------------------'
' Makes the user change H0l1d@y$ password at first logon
' -------------------------------------------------------'
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")
strContainer = strContainer & strDNSDomain
set objOU =GetObject("LDAP://" & strContainer )
For each objUser in objOU
If objUser.class="user" then
objUser.SetPassword strPassword
objUser.SetInfo
objUser.Put "pwdLastSet",intPwdValue
objUser.SetInfo
objUser.Put "userAccountControl",intAccValue
objUser.SetInfo
intCounter = intCounter +1
End if
next
WScript.Echo strPassword & " is Password. UserAccountValue = " _
& intAccValue & vbCr & intCounter & " accounts changed"
WScript.Quit
' End of change password example VBScript
--------------
在测试机上通过了,在真实环境没有通过。不知道怎么回事,唉,对VB不熟呀
---
我吃过这个亏,慎用。
原文链接:https://www.f2er.com/vb/262921.html