添加Windows用户如何使密码不过期?
用下面的一段代码可以向Windows添加用户,可是如何使新加的用户密码不会过期?Func _Add_LocalUser($sNewUsrName, $sNewUsrPass, $sNewUsrFull = "", $sNewUsrDesc = "")
;;;;;检查用户名是否合法
If StringStripWS($sNewUsrName,8) = "" Then
MsgBox(16,"Error","Invalid User Name !")
Return False
EndIf
;;;;;;;检测用户是否已存在!
TrayTip("Working Hard....","Checking User ....",5,1)
$isWorking = True
$strComputer="."
$colLocalComputer = ObjGet("WinNT://" & $strComputer)
If @error Then
MsgBox(16,"Error","Can Not Get The Object(WinNT://) !"
$isWorking = False
Return False
EndIf
Dim $user=["user"]
$colLocalComputer.Filter = $user
For $objuser In $colLocalComputer
If $objuser.Name = $sNewUsrName Then
TrayTip("Error","User "&$objuser.Name&" Already Exist !",3,3)
MsgBox(16,"Error","User "&$objuser.Name&" Already Exist !")
$isWorking = False
Return
EndIf
Next
;;;;;;;添加用户
TrayTip("Working Hard....","Adding User "&$sNewUsrName&" ....",10,1)
Local $colLocalComputer, $objUser
$colLocalComputer = ObjGet("WinNT://" & @ComputerName)
If @error Then
TrayTip("Error","Can Not Get The Object(WinNT://) !",5,3)
MsgBox(16,"Error","Can Not Get The Object(WinNT://) !")
$isWorking = False
Return False
EndIf
$objUser = $colLocalComputer.Create ("user", $sNewUsrName)
$objUser.SetPassword ($sNewUsrPass)
$objUser.Put ("Fullname", $sNewUsrFull)
$objUser.Put ("Description", $sNewUsrDesc)
$objUser.SetInfo
TrayTip("Working Hard....","User "&$user&" Added !",3,1)
$isWorking = False
;TrayTip("Working Hard....","",1)
Return True
EndFunc
[ 本帖最后由 hehui 于 2008-9-16 10:36 编辑 ] 還沒有人? 还是没有人来?
:face (32): VBS脚本设置用户密码永不过期
strComputer = "."
Dim user
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount")
For Each user1 In colItems
If user1.Name = "xxxxxx" Then
Set objUser = GetObject("WinNT://" & strComputer & "/" & user1.name)
If Not objUser.UserFlags AND ADS_UF_DONT_EXPIRE_PASSWD Then
objPasswordNoExpire = objUser.UserFlags XOR ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userFlags", objPasswordNoExpire
objUser.SetInfo
End If
End If
Next 已解决!
谢楼上的朋友!
加上一条:
$objUser.Put ("userFlags", 0x10000) 很好很强大
页:
[1]