+ Post New Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
Scripts Thread, Log logons in Coding and Web Development; ...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,945
    Thank Post
    886
    Thanked 1,696 Times in 1,474 Posts
    Blog Entries
    12
    Rep Power
    447

    Log logons

    Hi

    I plan to add a few lines to out logon script to check who has logged onto a machine in the event of damage & to trace where a user has been logging on.

    So I will need to lots, a log file that will display where a user has logged on & who has logged onto a particular machine. I would like to log the time and date as well.

    I have no idea how to do this though. Please can someone post there’s if they have done the same or point me into the right direction please?
    Cheers

    Z

  2. #2

    Join Date
    Feb 2006
    Location
    Derbyshire
    Posts
    1,381
    Thank Post
    181
    Thanked 211 Times in 171 Posts
    Rep Power
    65
    You should have this in the event log on the server assuming you mean networked PCs? Can't remember the event ID's but there's one for log on, one for log off. The only problem with any kind of script like this is the log off part never really takes into account crashes/random reboots/power outage... There's also been a script posted here before to log to MySQL or plain text if you use the search.

  3. #3

    JJonas's Avatar
    Join Date
    Jan 2008
    Location
    North Walsham, Norfolk
    Posts
    3,106
    Thank Post
    386
    Thanked 432 Times in 320 Posts
    Rep Power
    383
    add to logon script something like this...


    echo %date% %time% %computername% %username% >>\\MyServerName\logon$\logons.txt


    works for me.

  4. Thanks to JJonas from:

    goodhead (20th March 2009)

  5. #4
    tomscaper's Avatar
    Join Date
    Jul 2006
    Posts
    814
    Thank Post
    118
    Thanked 29 Times in 15 Posts
    Rep Power
    22
    Would the script cause any problems regarding many students logging on at once, and all trying to write to the same file at the same time. As i was interested in using this as well.

  6. #5

    Join Date
    Mar 2007
    Posts
    307
    Thank Post
    3
    Thanked 9 Times in 8 Posts
    Rep Power
    17
    The logon script I use was posted on here. It creates a log txt file for each computer & users so you can trace computer history and users history if you need.

    I'm sure you'll find it if you do a search on here

    Take a look at this Limit Logon VBS Version - EduGeek.net Forums
    Last edited by pallen; 28th April 2008 at 10:33 AM.

  7. #6
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,525
    Thank Post
    106
    Thanked 89 Times in 75 Posts
    Blog Entries
    46
    Rep Power
    40
    Quote Originally Posted by JJonas View Post
    add to logon script something like this...


    echo %date% %time% %computername% %username% >>\\MyServerName\logon$\logons.txt


    works for me.
    i do it like

    Code:
    for /f "tokens=1,2,3* delims=/ " %%a in ('date /t') do set date=%%a%%b%%c%%d
    for /f "tokens=1,2 delims=:" %%a in ('time /t') do set time=%%a%%b
    echo %date%,%time%,%username% >> \\backup\logs$\computer\%computername%.txt
    echo %date%,%time%,%computername% >> \\backup\logs$\user\%username%.txt
    cos sometimes its helpful to cross-reference

    I also do

    Code:
    ipconfig | find "IP Address" > \\backup\logs$\ips\%computername%.txt
    and

    Code:
    rem log mac addresses
    del \\backup\logs$\lapmacs\%computername%.log /q >nul
    for /f "tokens=2 delims=:" %%a in ('ipconfig /all ^| find "physical" /i ') do (
    	for /f %%b in ('cscript //nologo \\server1\netlogon\strip.vbs %%a') do (
    		rem set MACSTR=%%b 
    		echo %computername% > \\backup\logs$\lapmacs\%%b.log
    		echo %%b >> \\backup\logs$\lapmacs\%computername%.log
    	)
    )

  8. #7

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,945
    Thank Post
    886
    Thanked 1,696 Times in 1,474 Posts
    Blog Entries
    12
    Rep Power
    447
    Quote Originally Posted by OutToLunch View Post
    You should have this in the event log on the server assuming you mean networked PCs? Can't remember the event ID's but there's one for log on, one for log off. The only problem with any kind of script like this is the log off part never really takes into account crashes/random reboots/power outage... There's also been a script posted here before to log to MySQL or plain text if you use the search.
    Yes i know but we are after something that is easier to view etc.

    Quote Originally Posted by JJonas View Post
    add to logon script something like this...


    echo %date% %time% %computername% %username% >>\\MyServerName\logon$\logons.txt


    works for me.
    Thanks i will look into it

    Quote Originally Posted by browolf View Post
    i do it like

    Code:
    for /f "tokens=1,2,3* delims=/ " %%a in ('date /t') do set date=%%a%%b%%c%%d
    for /f "tokens=1,2 delims=:" %%a in ('time /t') do set time=%%a%%b
    echo %date%,%time%,%username% >> \\backup\logs$\computer\%computername%.txt
    echo %date%,%time%,%computername% >> \\backup\logs$\user\%username%.txt
    cos sometimes its helpful to cross-reference

    I also do

    Code:
    ipconfig | find "IP Address" > \\backup\logs$\ips\%computername%.txt
    and

    Code:
    rem log mac addresses
    del \\backup\logs$\lapmacs\%computername%.log /q >nul
    for /f "tokens=2 delims=:" %%a in ('ipconfig /all ^| find "physical" /i ') do (
    	for /f %%b in ('cscript //nologo \\server1\netlogon\strip.vbs %%a') do (
    		rem set MACSTR=%%b 
    		echo %computername% > \\backup\logs$\lapmacs\%%b.log
    		echo %%b >> \\backup\logs$\lapmacs\%computername%.log
    	)
    )

    I will also look into this one


    Thanks alot guys

  9. #8

    Join Date
    Jul 2007
    Location
    Nottingham
    Posts
    196
    Thank Post
    19
    Thanked 7 Times in 7 Posts
    Rep Power
    16
    We use an Access DB to log all Logon and Logoff Events:

    strAS = "\\DC-01\File_Store\Auditdb"

    if not objFSO.FileExists(strAS & "\Logon.mdb") Then
    objFSO.CopyFile "" & strAS & "\default\logon.mdb", "" & strAS & "\logon.mdb", True
    end if

    Set objConn = CreateObject("ADODB.Connection")
    objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strAS & "\Logon.mdb"
    objConn.Execute "INSERT INTO Logon (Operation, UserName, OU, ComputerName, Date1, Time1) VALUES ('Logon', """ & strUserName & """, '" & strOU & "', '" & strComputerName & "', " & strDate & ", #" & Time & "#)"
    objConn.Close

    If err.number then msgbox "Unable to write to the logon/logoff audit database. Please contact the Technicians."

    Set objConn = Nothing

    Function strFormatDate(strDate)
    'Returns the formatted Date

    Dim intday, year, datelength, day
    Dim dayLength, iYear, iMonth, iDay

    datelength = len(strDate)

    intday = InStr(1, strDate, "/")
    year = InStrRev (strDate, "/")

    dayLength = year - intday - 1
    day = mid( strDate, intday + 1, dayLength )

    iYear = Right( strDate, dateLength-year )
    iMonth = Left( strDate, intday - 1 )

    iDay = day

    strDate = "#" & iDay & "/" & iMonth & "/" & iYear & "#"
    strFormatDate = strDate

    End Function

  10. #9

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,945
    Thank Post
    886
    Thanked 1,696 Times in 1,474 Posts
    Blog Entries
    12
    Rep Power
    447
    Ok so if i have read this script right, this is the location of the database:

    \\DC-01\File_Store\Auditdb\logon.mdb

    And if the database does not exist it will copy it from another location?

    Thanks for that script just what i am after.
    Last edited by FN-GM; 28th April 2008 at 08:28 PM.

  11. #10

    Join Date
    Jul 2007
    Location
    Nottingham
    Posts
    196
    Thank Post
    19
    Thanked 7 Times in 7 Posts
    Rep Power
    16
    Not quite. Basicly you have a backup copy just in case you need to move the current log elsewhere for checking.

    \\DC-01\File_Store\Auditdb\logon.mdb is just the UNC path to where you want the database to be stored. You'll need to give authenticated users Modify access to it so I suggest you hide it away somewhere (hidden share or such like).

    I've attached the basic DB, it only a table but makes life easy when you need to search all the computers on the network to see where a kid has logged on.
    Attached Files Attached Files

  12. #11

    Join Date
    Jul 2007
    Location
    Nottingham
    Posts
    196
    Thank Post
    19
    Thanked 7 Times in 7 Posts
    Rep Power
    16
    Quote Originally Posted by FN-Greatermanchester View Post
    And if the database does not exist it will copy it from another location?
    I really need to learn to read...

  13. #12

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,945
    Thank Post
    886
    Thanked 1,696 Times in 1,474 Posts
    Blog Entries
    12
    Rep Power
    447
    Just the job, cheers

  14. #13

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,945
    Thank Post
    886
    Thanked 1,696 Times in 1,474 Posts
    Blog Entries
    12
    Rep Power
    447
    sorry show do you log a logoff please?

    Thanks

  15. #14


    Join Date
    Oct 2006
    Posts
    3,411
    Thank Post
    184
    Thanked 356 Times in 285 Posts
    Rep Power
    148
    ^ Put the same script in "logoff scripts" instead of "logon sscripts" in GP

  16. #15

    Join Date
    Jul 2007
    Location
    Nottingham
    Posts
    196
    Thank Post
    19
    Thanked 7 Times in 7 Posts
    Rep Power
    16
    Have 2 scripts, one for logon and another for logoff. They'll both be the same apart from the value of the Operation field in the SQL statement. There is probably a way for the script to detect if its a logon or logoff but thats beyond me.

SHARE:
+ Post New Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Concurrent logons
    By mrforgetful in forum Wireless Networks
    Replies: 7
    Last Post: 28th February 2008, 05:33 PM
  2. Restricting Logons
    By Espada in forum Windows
    Replies: 2
    Last Post: 6th December 2007, 05:51 PM
  3. Really slow logons
    By dezt in forum Wireless Networks
    Replies: 8
    Last Post: 28th August 2007, 08:43 AM
  4. Track user logons?
    By Jon1 in forum Windows
    Replies: 33
    Last Post: 22nd June 2007, 02:44 PM
  5. Slow Logons
    By andyrite in forum Windows
    Replies: 3
    Last Post: 24th April 2007, 09:48 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •