Password expiration script from Bginfo

Forums Desktop Info Password expiration script from Bginfo

Viewing 3 reply threads
  • Author
    Posts
    • #2568 Reply
      AvatarAndreas Hanfelt

      Maybe someone can help here, i have an really old script that was used with bginfo to display when a user needs to change password and how many days are left. I cant get this to work with Display info though.

      Here is the script:

      On Error Resume Next
      
      Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
      Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
      Const ONE_HUNDRED_NANOSECOND    = .000000100
      Const SECONDS_IN_DAY            = 86400
      
      Set objADSystemInfo = CreateObject("ADSystemInfo")              ' LINE 8
      Set objUser = GetObject("LDAP://" & objADSystemInfo.UserName)   ' LINE 9
      
      intUserAccountControl = objUser.Get("userAccountControl")
      If intUserAccountControl And ADS_UF_DONT_EXPIRE_PASSWD Then
          Echo "Ditt Lösnordet upphör aldrig."
          WScript.Quit
      Else
          dtmValue = objUser.PasswordLastChanged
          If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
              Echo "Du har aldrig ändrat ditt lösenord."
              WScript.Quit
          Else
              intTimeInterval = Int(Now - dtmValue)
              Echo "Du bytte ditt lösenord " & _
                DateValue(dtmValue) '& " den " & TimeValue(dtmValue) & vbCrLf & _
      		 ' DateValue(dtmValue) & " den " & TimeValue(dtmValue) & vbCrLf & _
               ' "The difference between when the password was last" & vbCrLf & _
               ' "set and today is " & intTimeInterval & " days"
          End If
      
          Set objDomain = GetObject("LDAP://" & objADSystemInfo.DomainDNSName)
          Set objMaxPwdAge = objDomain.Get("maxPwdAge")
      
          If objMaxPwdAge.LowPart = 0 Then
             ' Echo "The Maximum Password Age is set to 0 in the " & _
             '              "domain. Therefore, the password does not expire."
              WScript.Quit
          Else
              dblMaxPwdNano = _
                  Abs(objMaxPwdAge.HighPart * 2^32 + objMaxPwdAge.LowPart)
              dblMaxPwdSecs = dblMaxPwdNano * ONE_HUNDRED_NANOSECOND
              dblMaxPwdDays = Int(dblMaxPwdSecs / SECONDS_IN_DAY)
              ' Echo "Lösenordet måste bytas inom " & dblMaxPwdDays & " dagar"
      
              If intTimeInterval >= dblMaxPwdDays Then
                  Echo "Ditt lösenord har gått ut."
              Else
                  Echo "och du måste byta senast " & _
                    DateValue(dtmValue + dblMaxPwdDays) & vbCrLf &  "eller inom " & _
                    Int((dtmValue + dblMaxPwdDays) - Now) & " dagar."
              End If
          End If
      End If

      Dont really know how to execute but i guess its like:
      CMD=file:cscript,parameters:passwordExpires.vbs

      The script will only show Microsoft (R) Windows Script Host version 5.812 in display info.

      0
    • #2569 Reply
      AvatarAndreas Hanfelt

      New script that works changed Echo to StdOut. Now i need to find a way to skip the first two lines that gets printed when running the script. “Microsoft (R) Windows Script Host version 5.812
      Copyright (C) Microsoft Corporation. Med ensamrätt.”

      On Error Resume Next
      
      Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
      Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
      Const ONE_HUNDRED_NANOSECOND    = .000000100
      Const SECONDS_IN_DAY            = 86400
      
      Set objADSystemInfo = CreateObject("ADSystemInfo")              ' LINE 8
      Set objUser = GetObject("LDAP://" & objADSystemInfo.UserName)   ' LINE 9
      
      Set objStdOut = WScript.StdOut
      
      intUserAccountControl = objUser.Get("userAccountControl")
      If intUserAccountControl And ADS_UF_DONT_EXPIRE_PASSWD Then
          objStdOut.Write "Ditt Lösnordet upphör aldrig."
          WScript.Quit
      Else
          dtmValue = objUser.PasswordLastChanged
          If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
              objStdOut.Write "Du har aldrig ändrat ditt lösenord."
              WScript.Quit
          Else
              intTimeInterval = Int(Now - dtmValue)
              objStdOut.Write "Du bytte ditt lösenord " & _
                DateValue(dtmValue) '& " den " & TimeValue(dtmValue) & vbCrLf & _
      		 ' DateValue(dtmValue) & " den " & TimeValue(dtmValue) & vbCrLf & _
               ' "The difference between when the password was last" & vbCrLf & _
               ' "set and today is " & intTimeInterval & " days"
          End If
      
          Set objDomain = GetObject("LDAP://" & objADSystemInfo.DomainDNSName)
          Set objMaxPwdAge = objDomain.Get("maxPwdAge")
      
          If objMaxPwdAge.LowPart = 0 Then
             ' objStdOut.Write "The Maximum Password Age is set to 0 in the " & _
             '              "domain. Therefore, the password does not expire."
              WScript.Quit
          Else
              dblMaxPwdNano = _
                  Abs(objMaxPwdAge.HighPart * 2^32 + objMaxPwdAge.LowPart)
              dblMaxPwdSecs = dblMaxPwdNano * ONE_HUNDRED_NANOSECOND
              dblMaxPwdDays = Int(dblMaxPwdSecs / SECONDS_IN_DAY)
              ' objStdOut.Write "Lösenordet måste bytas inom " & dblMaxPwdDays & " dagar"
      
              If intTimeInterval >= dblMaxPwdDays Then
                  objStdOut.Write "Ditt lösenord har gått ut."
              Else
                  objStdOut.Write "och du måste byta senast " & _
                    DateValue(dtmValue + dblMaxPwdDays) & vbCrLf &  "eller inom " & _
                    Int((dtmValue + dblMaxPwdDays) - Now) & " dagar."
              End If
          End If
      End If
      0
    • #2570 Reply
      AvatarAndreas Hanfelt

      And it was fixed by changing cscript to wscript 😉

      CMD=file:wscript,parameters:passwordExpires.vbs

      1+
    • #2572 Reply
      GlennGlenn
      Keymaster

      nice work!

      0
Viewing 3 reply threads
Reply To: Password expiration script from Bginfo
Your information:




Do NOT follow this link or you will be banned from the site!