Page 2 of 2 <12
Topic Options
#62141 - 2002-03-11 02:51 PM Re: Script for determining NT account expiry?
attiahia Offline
Hey THIS is FUN

Registered: 2000-03-27
Posts: 268
NTDOC

thanks a lot for your hlp.
The value of the mentioned key in my workstation is 5,0,00,0 which mean Windows 2000/DSClient.

LLigetfa

Your idea is excellent and this what I already start to do but before I continue I like to say the following.

This code

$usr = GetObject("WinNT://"+@LDOMAIN+"/"+@UserID+",user")
$AccountExpirationDate = $usr.AccountExpirationDate
? @UserID+" - AccountExpirationDate = "+$AccountExpirationDate

Is exactly what I want and it gave me the expiration date but the question is:

When I tested the code locally (C:\Kix32 Script.Kix) on one of our user BC it did not work because the BC does not have ADSI.
Now, in the real situation when I place this script on the domain controller where ADSI is installed, will the script work fine?

I mean is there a way to run this part of the script on the domain controller?

Or this code require ADSI to be installed on the user BC it self?

Thanks a lot For this great help. [Smile]

[ 11 March 2002, 14:53: Message edited by: attiahia ]

Top
#62142 - 2002-03-11 03:27 PM Re: Script for determining NT account expiry?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Regardless of where you place the script, the determining factor is where the script will run. If it is in the logon script, even though it is in the NetLogon share of the DC, it still runs on the local client so ADSI would have to be installed.

My sample script $usr = GetObject("WinNT://"+@LDOMAIN+"/"+@UserID+",user") is intended to run on the client and requires ADSI. An admin script would be separate from the logon script and scheduled to run periodically on one machine with ADSI installed. You could use Task Scheduler for that.

The following sample will create an entry in and INI file only for those users that have an expiration set.
code:
 break on
$WorkDir ="C:\KiX4.02"
$domain = GetObject("WinNT://"+@domain)
$domain.filter = "user",""
for each $user in $domain
$AccountExpirationDate = $user.AccountExpirationDate
$UserName = $user.name
$RC = WriteProfileString($WorkDir + "\Users.ini","$UserName","AccountExpirationDate",$AccountExpirationDate)
next
get $_

After that all that is needed is to ReadProfileString() from the logon script and you're good to go.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#62143 - 2002-03-14 03:25 PM Re: Script for determining NT account expiry?
attiahia Offline
Hey THIS is FUN

Registered: 2000-03-27
Posts: 268
LLigetfa
I received great support from you.
Thank you and thanks for every one.

Top
#62144 - 2002-03-18 06:47 AM Re: Script for determining NT account expiry?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I was playing around with the AccountExpirationDate properties and found that a failure to resolve $user.AccountExpirationDate properly can invalidate an entire string that was to be printed to the screen. This behavior somewhat surprised me and can be demonstrated using the following code. The basic issue that this teaches is all COM calls should be fed into variables and NOT concatenated into a string using a plus sign.

When you execute this code, the text "ExpDate2" is not printed at all when the account is configured NOT to expire. The call $User.AccountExpirationDate returns an error apparently nullifying the entire string.

I do not believe that this is an issue that needs any resolution. I bring it up so that everyone is aware that using a plus sign (+) in these circumstances can potentially cause them a problem.

To test:
; Setup User1 with account set to NEVER expire.
; Setup User2 with an account set to Expire on some date
; Be sure to configure a Fullname for each account to verify that the script continues to run properly.
; Execute with USER1, edit then execute for User2

$User = GetObject("WinNT://@Ldomain/User1,user")

? "Name: " + $User.name
? "ExpDate1: " $User.AccountExpirationDate
? "ExpDate2: " + $User.AccountExpirationDate
$Date = $User.AccountExpirationDate
? "ExpDate3: $Date"
? "Error:@Error@CRLF@Serror"
? "FullName: " + $User.fullname

[ 18 March 2002, 14:59: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#62145 - 2002-03-18 02:36 PM Re: Script for determining NT account expiry?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Howard,
I came across the same issue in the beta section some time ago.

WMI String to Number gives error

It was not the main topic, just an observation that nobody addressed.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 2 of 2 <12


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1821 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.056 seconds in which 0.033 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org