(view source code of pwdnoexp.vbs as plain text)
Option Explicit
Dim colItems, objItem, objSysInfo, objWMISvc
Dim objPasswordExpirationFlag, objUser, objUserFlags
Dim strComputer, strDomainOrWorkgroup, strUser
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
' Check command line argument(s)
With WScript.Arguments
If .Named.Count > 0 Then Syntax
If .Unnamed.Count <> 1 Then Syntax
strUser = .Unnamed(0)
End With
' Retrieve workgroup or domain name
Set objWMISvc = GetObject( "winmgmts:\\.\root\cimv2" )
Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
For Each objItem in colItems
strDomainOrWorkgroup = objItem.Domain
Next
' Retrieve computer name
Set objSysInfo = CreateObject( "WinNTSystemInfo" )
strComputer = objSysInfo.ComputerName
' Get the user account object
Set objUser = GetObject( "WinNT://" & strDomainOrWorkgroup & "/" & strComputer & "/" & strUser & ",User" )
' Read the user account "flags" (settings)
objUserFlags = objUser.Get( "UserFlags" )
' Change a single bit in the user account flags
objPasswordExpirationFlag = objUserFlags OR ADS_UF_DONT_EXPIRE_PASSWD
' Change the user account flags
objUser.Put "userFlags", objPasswordExpirationFlag
' Commit the changes
objUser.SetInfo
' Release the objects
Set objUser = Nothing
Set objSysInfo = Nothing
Set colItems = Nothing
Set objWMISvc = Nothing
Function Capitalize( myString, myChars )
' This function capitalizes a string, in this case the script name,
' so the on screen help will display the proper capitalization
' even if PwdNoExp.vbs is renamed to PasswordNeverExpires.vbs
Dim arrChars, i, intStart, strResult
If myChars <> "" Then
strResult = LCase( myString )
arrChars = Split( myChars, "," )
intStart = 1
For i = 0 To UBound( arrChars )
intStart = InStr( intStart + 1, strResult, arrChars(i), vbBinaryCompare )
strResult = Replace( strResult, LCase( arrChars(i) ), arrChars(i), intStart + 1, 1, vbBinaryCompare )
Next
Else
strResult = UCase( Left( myString ) ) _
& LCase( Mid( myString ) )
End If
Capitalize = strResult
End Function
Sub Syntax
Dim strMsg
strMsg = strMsg & vbCrLf _
& Capitalize( WScript.ScriptName, "P,N,Ex" ) _
& ", Version 1.00" & vbCrLf _
& "Set password expiration date to NEVER for a local user ID" _
& vbCrLf & vbCrLf _
& "Usage: [ CSCRIPT ] " & UCase( WScript.ScriptName ) & " user_id" _
& vbCrLf & vbCrLf _
& "Where: " & Chr(34) & "user_id" & Chr(34) _
& " is the local user whose password should never expire" _
& vbCrLf & vbCrLf _
& "Based on a Microsoft TechNet Script Center sample:" & vbCrLf _
& "www.microsoft.com/technet/scriptcenter/scripts" _
& "/ds/local/users/lousvb14.mspx" _
& vbCrLf & vbCrLf _
& "Written by Rob van der Woude" & vbCrLf _
& "http://www.robvanderwoude.com"
WScript.Echo strMsg
WScript.Quit(1)
End Sub
page last modified: 2024-04-16; loaded in 0.0094 seconds