Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Windows Login Timer
 

Vbscript / Operating System / Windows Login Timer

This script calculates the login time based on the time at which the user authentication occurs and the time at which the script is run i.e. the time between login and when the first application can be run. The script can be run as a login script or placed in the startup folder to run automatically after login. Use this script to calculate the time taken to download a roaming profile and perform any other Windows startup activities. User access to the local event log is required to read the application log entry indicating a successful authentication.



Set objShell = CreateObject("Wscript.Shell")
Set objNet = CreateObject("Wscript.Network")

intNumberID = 528
intEvent = 1
intRecordNum = 1

strComputer = "."
strFileName = "Logintimes.txt"
strFolder = "C:\"
strPath = strFolder & strFileName

endTime = Now()

Set objFso = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists(strFolder) Then
    Set objFolder = objFSO.GetFolder(strFolder)
Else
   Set objFolder = objFSO.CreateFolder(strFolder)
   Wscript.Echo "Folder created " & strFolder
End If
Set strFile = objFso.OpenTextFile(strPath, 8, True)

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Security)}!\" & _
        strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_NTLogEvent WHERE LogFile=`Security`")

intEvent = 1
hightime = 0

For Each objEvent in colLogFiles

If objEvent.EventCode = intNumberID AND (NOT objEvent.User = "NT AUTHORITY\NETWORK SERVICE") Then

startTime = WMIDateStringToDate(objEvent.TimeWritten)

LoginTime = DateDiff("s", startTime, endTime)

strLogin =  "User: " & objEvent.User & vbCRLF & "Start Time: " & startTime & vbCRLF & "End time: " & endTime & vbCRLF & vbCRLF & "Login time: " & LoginTime & " seconds"

strFile.WriteLine (strLogin)
strFile.WriteLine ()

Wscript.Echo strLogin

objShell.LogEvent 4,"User Logon Finished: " & objNet.Username & vbCRLf & strLogin

Wscript.Quit
End if

Next


Function WMIDateStringToDate(dtmInstallDate)
    WMIDateStringToDate = CDate(Mid(dtmInstallDate, 7, 2) & "/" & _
         Mid(dtmInstallDate, 5, 2) & "/" & Left(dtmInstallDate, 4) _
             & " " & Mid (dtmInstallDate, 9, 2) & ":" & _
                 Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, _
                     13, 2))
End Function





Please note that a disclaimer applies to any code on this page.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
     - General
     - Ms Office
     - Operating System
          - Add Remove Windows Server 2003 Components
          - Add Remove Windows Vista Components
          - Add Remove Windows Xp Components
          - Autologon And Runonce
          - Change Display Resolution
          - Change Location I386 Setup Files
          - Change Offline Folder Cache Location
          - Dell Bios Set Boot Device Order
          - Dell Bios Set Configuration Settings
          - Dell Bios View Configuration Settings
          - Dell Bios View Device Boot Order
          - Disable Vista User Account Control
          - Enumerate Cd Drives
          - Enumerate Computer Drives
          - Enumerate Disk Volumes
          - Enumerate Registry Keys
          - Flush Remote Dns Cache
          - Get Machine Hardware Model
          - Read Registry Key
          - Rename Computer
          - Rename Dell Machine By Service Tag
          - Set Internet Explorer Homepage
          - Set Random Desktop Wallpaper On Startup
          - Start And Stop A Service
          - Windows Login Timer
     - Processes And Services
     - Text Processing
     - User Interaction
     - Web Servers