Advertisement
Guest User

User Session Log - Logoff

a guest
May 21st, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim vaEndSessionData(5)
  2.  
  3. 'Get date and time.
  4. vaEndSessionData(0)=Date
  5. vaEndSessionData(1)=Time
  6. strTimeNow = Date & " " & Time
  7.  
  8. 'Get time of logon and calculate difference
  9. Set objTemp = WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2)
  10. Set objFSO = CreateObject("Scripting.FileSystemObject")
  11. Set objFile = objFSO.OpenTextFile(objTemp & "\Logon_Time.tmp", 1)
  12. strTimeThen = objFile.ReadLine
  13. objFile.Close
  14.  
  15. intSecsDifferent=DateDiff("s", strTimeThen, strTimeNow)
  16. vaEndSessionData(2)=intSecsDifferent
  17.  
  18. Function SplitSec(pNumSec)
  19.   Dim d, h, m, s
  20.   Dim h1, m1
  21.  
  22.   d = int(pNumSec/86400)
  23.   h1 = pNumSec - (d * 86400)
  24.   h = int(h1/3600)
  25.   m1 = h1 - (h * 3600)
  26.   m = int(m1/60)
  27.   s = m1 - (m * 60)
  28.  
  29.   SplitSec = cStr(d) & "d " & cStr(h) & "h " & cStr(m) & "m " & cStr(s) & "s"
  30. End Function
  31.  
  32. vaEndSessionData(3)=SplitSec(intSecsDifferent)
  33.  
  34. 'Update some local computer information
  35.  
  36. strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress > ''"
  37.  
  38. Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
  39. Set colItems      = objWMIService.ExecQuery( strQuery, "WQL", 48 )
  40.  
  41. 'Get some useful local computer information
  42. strComputer = "."
  43. Set objWMIService = GetObject("winmgmts:" _
  44.     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  45. Set colSettings = objWMIService.ExecQuery _
  46.     ("Select * from Win32_OperatingSystem")
  47. For Each objOperatingSystem in colSettings
  48.     vaEndSessionData(4)=objOperatingSystem.FreePhysicalMemory
  49. Next
  50.  
  51. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  52. Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
  53. For Each objItem in colItems
  54.     vaEndSessionData(5)=objItem.LoadPercentage
  55. Next
  56.  
  57. 'write out to file and clean up
  58. vJoinedArray=(join(vaEndSessionData,","))
  59.  
  60. Set objTemp = WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2)
  61. Set objFSOr = CreateObject("Scripting.FileSystemObject")
  62. Set objFiled = objFSOr.OpenTextFile(objTemp & ".\Session_Info.log", 1)
  63. strLogonInfo = objFiled.ReadLine
  64. objFiled.Close
  65.  
  66. 'Wscript.Echo strLogonInfo & "," & vJoinedArray
  67. strSessionInfo = strLogonInfo & "," & vJoinedArray
  68.  
  69. Dim objFileSystem, objOutputFile
  70. Dim strOutputFile
  71.  
  72. strOutputFile = "\\server.domain\share$\logfile.log"
  73.  
  74. Set objFileSystem = CreateObject("Scripting.fileSystemObject")
  75. Set objOutputFile = objFileSystem.OpenTextFile(strOutputFile, 8)
  76.  
  77. objOutputFile.WriteLine (strSessionInfo)
  78. objOutputFile.Close
  79.  
  80. Set objFileSystem = Nothing
  81.  
  82. Set objTemp = WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2)
  83. Set objFSO = CreateObject("Scripting.FileSystemObject")
  84. objFSO.DeleteFile(objTemp & "\Session_Info.log")
  85. objFSO.DeleteFile(objTemp & "\Logon_Time.tmp")
  86.  
  87. WScript.Quit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement