| John Smith 2004-03-31, 5:38 pm |
| Cool. I got it working with your help. Below is the function that returns
the values if anyone is interested. If there are better ways, please let me
know.
Thanks again.
///////////////// BEGIN ////////////////
public string getProviderProps(string strProperty,string strADsPath) {
const int MAXPASSWDAGE = 90;
DirectoryEntry deMain = new DirectoryEntry();
deMain.Path = "LDAP://SERVERPATH/" + strADsPath;
deMain.Username = "username";
deMain.Password = "password";
//get some properties and do things with them
//PasswordLastChanged
LargeInteger liPasswdLastSet = deMain.Properties["pwdLastSet"].Value as
LargeInteger;
//Convert the highorder/loworder parts to a long
long datePasswdLastSet = (((long)(liPasswdLastSet.HighPart) << 32) + (long)
liPasswdLastSet.LowPart);
//and convert it from FileTime to DateTime string
DateTime datePasswdLastSetVal = DateTime.FromFileTime(datePasswdLastSet);
///////////////////////////////////////////////////////////
//AccountExpiration
//return the expiration date if account is set to expire.
//accounts not set to expire will have 12/31/1600 7:00:00 PM
LargeInteger liAcctExpiration = deMain.Properties["accountExpires"].Value as
LargeInteger;
//Convert the highorder/loworder parts to a long
long dateAcctExpiration = (((long)(liAcctExpiration.HighPart) << 32) +
(long) liAcctExpiration.LowPart);
//and convert it from FileTime to DateTime
string strAcctExpiration =
DateTime.FromFileTime(dateAcctExpiration).ToString();
///////////////////////////////////////////////////////////
switch (strProperty) {
case "passwdexpirdate":
return datePasswdLastSetVal.AddDays(MAXPASSWDAGE).ToString();
break;
case "passwdlastchanged":
return DateTime.FromFileTime(datePasswdLastSet).ToString();
break;
case "passwdage":
return ((int)((DateTime.Now.Ticks/1000 - datePasswdLastSetVal.Ticks/1000) /
(1000 * 3600 * 24))/10 ).ToString();
break;
case "accountexpiration":
if(strAcctExpiration.IndexOf("1600") > 0)
return "Account expiration not set";
else
return strAcctExpiration;
break;
default:
return "Internal System Failure";
break;
}
}
///////////////END ///////////////////
"Willy Denoyette [MVP]" <willy.denoyette@pandora.be> wrote in message
news:%23P5tyE4EEHA.4080@TK2MSFTNGP09.phx.gbl...
> John,
> Inline ***
> Willy.
>
> "John Smith" <no_one_home@hotmail.com> wrote in message
> news:eL4oiI3EEHA.3372@TK2MSFTNGP10.phx.gbl...
>
> *** That's why you need to set a reference to activeds.tlb (or run
> tlbimp.exe to create the interop assembly), the __ComObject type is a
> Dispatch COM interface, you need to cast this to the LargeInteger class
> available through the interop assembly.
>
> LargeInteger li = user.Properties["pwdLastSet"].Value as LargeInteger;
> Convert the highorder/loworder parts to a long
> long date = (((long)(li.HighPart) << 32) + (long) li.LowPart);
> and convert it from FileTime to DateTime
> string dt = DateTime.FromFileTime(date).ToString();
>
>
can[color=darkred]
> ***
> Yes, using same code as above, but now retrieving the "accountExpires"
> property.
>
>
|