WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

wNT
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Keeping Track of Last User Login

Keywords:   track last user logon

;Delete old trace log
;FileDelete("C:\incoming\debug.txt")
;Enable debug trace (turned off now)
;DebugTrace(@on,"C:\incoming\debug.txt")

;Get 95 or NT platform info
OStype = WinVersion(4)

;Check for legal platform
IF OStype <> 4 && OStype <> 5 ; Is it Win NT or Win 9x ?
    exit ; if its NOT either we leave
endif

;We're only doing it for NT this week
IF OStype == 4 ; Win NT
    ;Load NT extender
    AddExtender("WWWNT34I.DLL")
    ;get number of days to check from from operator
    inp=askline("Check Users Last Logon","Please enter the amount of days you would like to check for users last logon, 90 days is the default","90")
    ;Save todays date
    time=timeymdhms()

    ;Get our Domain controller
    dc=wntGetDc( "", "", 1)
    ;message("DC",dc)

    ;Get lsit of all users
    UserList = WntUserList(dc,2)

    ;Get list of all PDC's and BDC's to check
    ServerList = wntServerList("","",16|8)

    ;Get count of the number of users found
    usercount=ItemCount(UserList,@tab)

    ;Get count of the number of PDC and BDS's found
    servercount=ItemCount(ServerList,@tab)


    ;Open a file to write output data to
    fil=Fileopen("userdata.txt","write")
	 Display(7,"Check Users Last Logon","Analyzing the network...*PLEASE WAIT*...there will be information box, letting you know when the processes has finished.")
	 Display(7,"Check Users Last Logon","Analyzing the network...this may take awhile...This process could take hours depending on your network..")
	 
    ;FOR EACH user in the list
    for a=1 to usercount
        ;Get name of this user
        User=ItemExtract(a,UserList,@tab)
        ;initialize newestlastlogon variale
        newestlastlogon="0000:00:00:00:00:00"

        ;Now that we have a user name, check all the PDC's and BDC's for this user
        for bb=1 to servercount
            ;Get a server name
            ServerX=ItemExtract(bb,ServerList,@tab)
            ;Get users last logon time from that server
            llog=WntUserGetDat(ServerX,User,"last_logon")
            ;Get users full name from that server
            nam=WntUserGetDat(ServerX,User,"full_name")

            ;If last logon time is newer than previous saved time
            ; (or initialized value) capture latest time
            if llog > newestlastlogon
               newestlastlogon=llog
            endif
        next

        ;Now the we checked all the servers for this user...
        ;Decide if we want to write any information

        ;Set write flag initially to false
        dowrite=@false

        if newestlastlogon=="0000:00:00:00:00:00"
           ; user never logged in.  Set write flag to true
           dowrite=@TRUE
        else
           ; or if last logon older than some time in the past...
           ; set the write flag to true then also
           if TimeDiffDays(time,newestlastlogon) > inp
              dowrite=@TRUE
           endif
        endif

        ;If the write flag was set to true...write out a long
        if dowrite==@TRUE
                inf = strcat('"',user,'" "',nam,'" "',newestlastlogon,'"')
                filewrite(fil,inf)
        endif


    next
    ;Close da file
    Fileclose(fil)

    message("Check Users Last Logon",'The report is finished! You can check out the report in the same directory as the program, in the file USERDATA.TXT. The report has " " around each entry so it can easily be transported into a spread sheet.')
endif  ; end of NT section
exit

Article ID:   W14643
Filename:   Keeping Track of Last User Login.txt
File Created: 2001:03:01:14:16:42
Last Updated: 2001:03:01:14:16:42