Hi there, I want to know how to get and convert the lastlogon from active directory? with the code below i can get some information but not the LastLogon, im getting System.__ComObject.
USING System.DirectoryServices.*.
USING System.DirectoryServices.AccountManagement.*.
DEFINE VARIABLE objContext AS PrincipalContext.
DEFINE VARIABLE objUser AS UserPrincipal.
DEFINE VARIABLE objDirEntry AS DirectoryEntry.
DEFINE VARIABLE PropertyValue AS CHARACTER NO-UNDO.
DEFINE VARIABLE PropertyName AS CHARACTER NO-UNDO.
PropertyName = "LastLogon".
objContext = NEW PrincipalContext(ContextType:Domain,"<DomainName").
objUser = UserPrincipal:FindByIdentity(objContext,"<UserName>").
PropertyValue = DYNAMIC-PROPERTY(objUser,PropertyName) NO-ERROR.
MESSAGE PropertyValue
VIEW-AS ALERT-BOX.
dLastLogon = TRUNCATE((((chRS:FIELDS("lastLogon"):VALUE:HighPart * EXP(2,32)) + chRS:FIELDS("lastLogon"):VALUE:Lowpart) / 600000000 + 60) / 1440, 0).
how to translate this to my code?
USING System.Collections.* FROM ASSEMBLY. USING System.DirectoryServices.* FROM ASSEMBLY. USING System.DirectoryServices.ActiveDirectory.DirectoryContext FROM ASSEMBLY. /* *************************** Definitions ************************** */ DEFINE VARIABLE oADContext AS System.DirectoryServices.ActiveDirectory.DirectoryContext. DEFINE VARIABLE oDirectoryEntry AS System.DirectoryServices.DirectoryEntry. DEFINE VARIABLE oSearch AS System.DirectoryServices.DirectorySearcher. DEFINE VARIABLE oResultAll AS System.DirectoryServices.SearchResultCollection. DEFINE VARIABLE oResult AS System.DirectoryServices.SearchResult. DEFINE VARIABLE oenum AS System.Collections.IEnumerator. DEFINE VARIABLE iCount AS INTEGER NO-UNDO. DEFINE VARIABLE cComputer AS CHARACTER NO-UNDO. DEFINE VARIABLE dLastLogon AS DECIMAL NO-UNDO. oADContext = NEW DirectoryContext(System.DirectoryServices.ActiveDirectory.DirectoryContextType:Domain). oDirectoryEntry = System.DirectoryServices.ActiveDirectory.Domain:GetDomain(oADContext):GetDirectoryEntry(). oSearch = NEW System.DirectoryServices.DirectorySearcher(oDirectoryEntry,SUBSTITUTE("(&&(objectClass=computer))")). oResultAll = oSearch:FindAll(). /* *************************** Main Block ************************** */ DO iCount=1 TO oResultAll:Count: /* Hier is het complete LDAP pad zichtbaar */ oDirectoryEntry = NEW System.DirectoryServices.DirectoryEntry(oResultAll[iCount]:path). oenum = oDirectoryEntry:Properties:GetEnumerator(). cComputer = oDirectoryEntry:Properties["CN":U]:Item[0]. IF cComputer = "PC10101" THEN DO: MESSAGE "ActiveDirectory Path: " SKIP oDirectoryEntry:Path SKIP (2) oDirectoryEntry:Properties["CN":U]:Item[0] SKIP oDirectoryEntry:Properties["objectCategory":U]:Item[0] SKIP oDirectoryEntry:Properties["LastLogon":U]:Value. VIEW-AS ALERT-BOX INFO BUTTONS OK. END. END. RETURN.
USING System.DirectoryServices.*.
USING System.DirectoryServices.AccountManagement.*.
DEFINE VARIABLE objContext AS PrincipalContext.
DEFINE VARIABLE objUser AS UserPrincipal.
DEFINE VARIABLE objDirEntry AS DirectoryEntry.
DEFINE VARIABLE PropertyValue AS CHARACTER NO-UNDO.
DEFINE VARIABLE PropertyName AS CHARACTER NO-UNDO.
PropertyName = "LastLogon".
objContext = NEW PrincipalContext(ContextType:Domain,"<DomainName").
objUser = UserPrincipal:FindByIdentity(objContext,"<UserName>").
PropertyValue = DYNAMIC-PROPERTY(objUser,PropertyName) NO-ERROR.
MESSAGE PropertyValue
VIEW-AS ALERT-BOX.
Thanks Tbergman
Many Thanks, allready done for computer