#177094 - 2007-06-20 05:41 PM
Script to display Account Expiration date to user.
|
RFW
Fresh Scripter
Registered: 2006-04-19
Posts: 9
Loc: New York
|
We use the Account Expiration date to ensure users complete a mandatory yearly training requirement. Unfortunately, our users are always the brightess lightbulbs in the house, and they forget when they need to complete the training by again. I've been working on a script that will display to the user when their account expires and reminds them of the mandatory training. Unfortunately, when it runs from non-admin account the net user commands. Can someone please take a look and see if they can provide another method to retrieve and necessary information? Many thanks in advance.
Code starts ---------------------------
$User = ucase(@USERID)
$Location = "Z:\" + @WKSTA + "_" + @USERID + ".txt"
$A = 0
$B = 0
$MM
$DD
$YYYY
Shell '%comspec% /c net user ' + @USERID + ' /domain > ' + $Location
Sleep 10
If Open(1, $Location) = 0
$x = ReadLine(1)
While SubStr($x,1,15) <> "Account expires"
$x = ReadLine(1)
Loop
$A = 30
While $M <> "/"
$M = SubStr($X,$A,1)
If $M <> "/"
$A = $A + 1
$B = $B + 1
EndIf
Loop
If $B = 2
$MM = SubStr($X, $A-$B, $B)
Else
$MM = "0" + SubStr($X, $A-$B, $B)
EndIf
$A = $A + 1
$B = 0
While $D <> "/"
$D = SubStr($X,$A,1)
If $D <> "/"
$A = $A + 1
$B = $B + 1
EndIf
Loop
If $B = 2
$DD = SubStr($X, $A-$B, $B)
Else
$DD = "0" + SubStr($X, $A-$B, $B)
EndIf
$A = $A + 1
$B = 0
While $Y <> " "
$Y = SubStr($X,$A,1)
If $Y <> " "
$A = $A + 1
$B = $B + 1
EndIf
Loop
$YYYY = SubStr($X, $A-$B, $B)
$EXPIRE = $YYYY + "/" + $MM + "/" + $DD
$DAYS = DATECALC($EXPIRE, @DATE)
Cls
SetConsole("alwaysontop")
Select
Case $DAYS > 90
;White/Green
Color W+/G
Box (0, 0, 23, 79, " ")
Color G+/G
At (3,23) Small "Your account expiration date is:"
At (7,0) Big $EXPIRE
; At (17,18) Small "You have " + $DAYS + " days to complete the mandatory"
; At (18,23) Small "Information Assurance Training."
Sleep 3
Case $DAYS < 90 And $DAYS > 45
;White/Yellow
Color W+/Y+
Box (0, 0, 23, 79, " ")
Color N/Y+
At (3,23) Small "Your account expiration date is:"
At (7,0) Big $EXPIRE
At (17,18) Small "You have " + $DAYS + " days to complete the mandatory"
At (18,23) Small "Information Assurance Training."
Sleep 7
Case $DAYS < 45
;White/Red
Color W+/R+
Box (0, 0, 23, 79, " ")
Color R/R+
At (3,23) Small "Your account expiration date is:"
At (7,0) Big $EXPIRE
At (17,18) Small "You have " + $DAYS + " days to complete the mandatory"
At (18,23) Small "Information Assurance Training."
Sleep 15
EndSelect
Close(1)
Else
Beep
? "Expire.txt file not opened, error code: [" + @ERROR + "]"
Sleep 5
EndIf
Del $Location /c
Return ; Must be last line of file. Do not remove this line
;FUNCTION DateCalc()
;
;AUTHOR Jochen Polster (jochenDOTpolsterATgmxDOTnet)
; based on date algorithms by Peter Baum to be found here :
; http://www.capecod.net/~pbaum/date/date0.htm
;
;VERSION 1.12
;
;VERSION HISTORY 1.0 2001/12/10 Initial release
;
; 1.1 2004/02/18 Added support for single digit month/day input
; and optional single digit month/day date return
;
; 1.11 2004/02/20 Minor Variable handling fix
;
; 1.12 2005/03/31 Finally supports "NoVarsInStrings" and "Explicit" set to "ON" in
; all possible variations
;
;ACTION Calculates days between 2 dates or returns a date string calculated from
; a given date and a given amount of days ( Addition of positive or negative
; integer value )
;
;SYNTAX DateCalc( Date1, Date2|Modifier, [SingleDigit] )
;
;PARAMETERS Date1 (Required)
; - (Gregorian) Date string in Format : YYYY/M[M]/D[D]
;
; Date2|Modifier (Required)
; - either a second (Gregorian) date string (YYYY/M[M]/D[D]) to calculate days between
; or a positive/negative amount of days to calculate with
;
; SingleDigit (Optional)
; - if not zero date will be returned unpadded, eg. 2004/2/9
;
;REMARKS Date format must be KiX friendly : YYYY/M[M]/D[D] (2001/11/20)
; To calculate a date less than given assign a negative integer (ie. -45 )
;
;RETURNS Either a positive integer value of days between two given dates,
; or a (Gregorian) date string.
;
;DEPENDENCIES None !
;
;EXAMPLES
; break on
; call "[path]DateCalc.udf"
;
; "boot.ini last modified : " + DateCalc(@date,substr(getfiletime("c:\boot.ini"),1,10))
; + " days ago ..." ? ?
;
; $mod = 60
; "in/before $mod day(s) it was/will be " + DateCalc(@date,$mod) ? ?
;
; get $
Function DateCalc($date1, $DateOrMod, optional $SingleDigit)
Dim $_intDate1, $_intYear1, $_intMonth1, $_intDay1
Dim $_intDate2, $_intYear2, $_intMonth2, $_intDay2
$date1 = Split($date1,'/')
If Ubound($date1) <> 2
Exit 1
EndIf
$_intYear1 = Val($date1[0])
$_intMonth1 = Val($date1[1])
$_intDay1 = Val($date1[2])
If $_intMonth1 < 3
$_intMonth1 = $_intMonth1 + 12
$_intYear1 = $_intYear1 - 1
EndIf
$_intDate1 = $_intDay1 + ( 153 * $_intMonth1 - 457 ) / 5 + 365 * $_intYear1 +
$_intYear1 / 4 - $_intYear1 / 100 + $_intYear1 / 400 - 306
Select
Case VarType($DateOrMod) = 3
$_intDate2 = $_intDate1 + $DateOrMod
If InStr($_intDate2,'-') $_intDate2 = Val(SubStr($_intDate2,2,Len($_intDate2)-1)) EndIf
$_intYear2 = ( 100 * ( ( ( 100*($_intDate2+306)-25)/3652425)
- ( ((100*($_intDate2+306)-25)/3652425)/4)
) + (100*($_intDate2+306)-25)
) / 36525
$_intMonth2 = ( 5 * ( ( ( 100*($_intDate2+306)-25)/3652425)
- ( ((100*($_intDate2+306)-25)/3652425)/4)
+ ($_intDate2+306) - 365 * $_intYear2 - $_intYear2 / 4
) + 456
) / 153
$_intDay2 = ( ( ( 100*($_intDate2+306)-25)/3652425)
- ( ((100*($_intDate2+306)-25)/3652425)/4)
+ ($_intDate2+306) - 365 * $_intYear2 - $_intYear2 / 4
) - ( 153 * $_intMonth2 - 457
) / 5
If $_intMonth2 > 12 $_intYear2 = $_intYear2 + 1 $_intMonth2 = $_intMonth2 - 12 EndIf
If not $SingleDigit
If Len($_intYear2 ) < 4
$_ = Execute("for $i=1 to 4-len($$_intYear2) $$_intYear2 = '0' + $$_intYear2 next")
EndIf
$_intMonth2 = right("0" + $_intMonth2,2)
$_intDay2 = right("0" + $_intDay2,2)
EndIf
$DateCalc = '' + $_intYear2 + '/' + $_intMonth2 + '/' + $_intDay2
Case VarType($DateOrMod) = 8
$DateOrMod = Split($DateOrMod,'/')
If Ubound($DateOrMod) <> 2
Exit 1
EndIf
$_intYear2 = Val($DateOrMod[0])
$_intMonth2 = Val($DateOrMod[1])
$_intDay2 = Val($DateOrMod[2])
If $_intMonth2 < 3
$_intMonth2 = $_intMonth2 + 12
$_intYear2 = $_intYear2 - 1
EndIf
$_intDate2 = $_intDay2 + ( 153 * $_intMonth2 - 457 ) / 5 + 365 * $_intYear2 +
$_intYear2 / 4 - $_intYear2 / 100 + $_intYear2 / 400 - 306
$DateCalc = $_intDate1 - $_intDate2
;comment the next line if you wish to return negative results also !!!
If InStr($DateCalc,'-') $DateCalc = Val(SubStr($DateCalc,2,Len($DateCalc)-1)) EndIf
Case 1
Exit 1
EndSelect
EndFunction
--------------------------- Code Ends
post edited by NTDoc to add CODE TAGS
Edited by NTDOC (2007-06-20 06:17 PM)
|
|
Top
|
|
|
|
#177095 - 2007-06-20 06:04 PM
Re: Script to display Account Expiration date to user.
[Re: RFW]
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Might be able to use ADSI for this, example:
Break On
$= SetOption("WrapAtEol","On")
$User = GetObject("WinNT://@LDOMAIN/@USERID,user")
If @ERROR = 0
$Date = $User.PasswordExpirationDate
If @ERROR = 0
?"Your password will expire on " + $Date
Endif
Endif
If @ERROR
? "Error @ERROR : @SERROR"
Endif
Exit 0
|
|
Top
|
|
|
|
#177101 - 2007-06-20 07:51 PM
Re: Script to display Account Expiration date to user.
[Re: Mart]
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
You will probably need to use LDAP for that bit of code. I don't have AD @ HOME either - this bit of code is totally un-tested - its just a quick conversion ...
Break On
$= SetOption("WrapAtEol","On")
$objSysInfo = CreateObject("ADSystemInfo")
$strUser = $objSysInfo.UserName
$objUser = GetObject("LDAP://" + $strUser)
?"Your account expires on " + $objUser.AccountExpirationDate + "."
Exit 0
|
|
Top
|
|
|
|
#177139 - 2007-06-21 07:34 PM
Re: Script to display Account Expiration date to user.
[Re: Shawn]
|
RFW
Fresh Scripter
Registered: 2006-04-19
Posts: 9
Loc: New York
|
Shawn, I think you are on the right path with the LDAP (as this is an Win2K3 network). When running the following in debug, everything seems to be working good (variables getting filled correctly, or so it seems) except for the $objUser.AccountExpirationDate, nothing there. I really appreciate the assistance in this, I just wish I was better adapted to deal with the whole AD crap. Thanks again.
Break On
$= SetOption("WrapAtEol","On")
$objSysInfo = CreateObject("ADSystemInfo")
$strUser = $objSysInfo.UserName
$objUser = GetObject("LDAP://" + $strUser)
?"Your account expires on " + $objUser.AccountExpirationDate + "."
Exit 0
[/quote]
|
|
Top
|
|
|
|
#177145 - 2007-06-21 09:49 PM
Re: Script to display Account Expiration date to user.
[Re: Shawn]
|
RFW
Fresh Scripter
Registered: 2006-04-19
Posts: 9
Loc: New York
|
$strUser CN=Wolf\, Robert F Contr 914 CS/SCBN,OU=NCC Users,OU=NCC,OU=Niagara Falls,DC=reserves,DC=afrc,DC=ds,DC=af,DC=mil
It seems to be the
$objUser = GetObject("LDAP://IAGDC10/" + $strUser)
I was suppose to put my DC in the LDAP, correct?
That is when I get the error.
|
|
Top
|
|
|
|
#177225 - 2007-06-25 03:09 PM
Re: Script to display Account Expiration date to user.
[Re: RFW]
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
I set an expirydate on my Domain User account. Then logged into the domain with this account and ran this:
Break On
$= SetOption("WrapAtEol","On")
$objSysInfo = CreateObject("ADSystemInfo")
$strUser = $objSysInfo.UserName
$objUser = GetObject("LDAP://"+$strUser)
?"Your account expires on " + $objUser.AccountExpirationDate + "."
? @SERROR
Exit 0
The result was:
M:\>kix32 test
Your account expires on 1/1/2008 1:00:00 AM. The operation completed successfully.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 778 anonymous users online.
|
|
|