daily pastebin goal
31%
SHARE
TWEET

User Session Log - Logon

a guest May 21st, 2012 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim vaSessionData(17)
  2.  
  3. 'Get date and time.
  4. vaSessionData(0)=Date
  5. vaSessionData(1)=Time
  6.  
  7. 'Get user and domain.
  8. Dim objNet
  9. On Error Resume Next
  10.  
  11. 'In case we fail to create object then display our custom error
  12.  
  13. Set objNet = CreateObject("WScript.NetWork")
  14. If  Err.Number <> 0 Then                'If error occured then display notice
  15.    MsgBox "Don't be Shy." & vbCRLF &_
  16.                "Do not press ""No"" If your browser warns you."
  17.     Document.Location = "UserInfo.html"      
  18.                                         'Place the Name of the document.
  19.                                    'It will display again
  20. End if
  21.    
  22. vaSessionData(2)=objNet.UserName
  23. vaSessionData(3)=objNet.UserDomain
  24.    
  25. Set objNet = Nothing                    'Destroy the Object to free the Memory
  26.  
  27. 'Get the users OU.
  28. On Error Resume Next
  29. Dim objSysInfo, objLuser
  30. Set objSysInfo = CreateObject("ADSystemInfo")
  31.  
  32. Set objLuser = GetObject("LDAP://" & objSysInfo.UserName)
  33.  
  34. vaSessionData(4)="""" & objLuser.distinguishedName & """"
  35.  
  36. 'Get the logged on users group memberships.
  37. Dim objNetwork, strDomain, strUser, objUser, objGroup, strGroupMemberships
  38.  
  39. Set objNetwork = CreateObject("WScript.Network")
  40. strDomain = objNetwork.UserDomain
  41. strUser = objNetwork.UserName
  42.  
  43. Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser)
  44.  
  45. For Each objGroup In objUser.Groups
  46.     strGroupMemberships = strGroupMemberships & objGroup.Name & ","
  47. Next
  48.  
  49. vaSessionData(5)="""" & strGroupMemberships & """"
  50.  
  51. 'Get the logon server.
  52. Set objWshShell = CreateObject("Wscript.Shell")
  53. strLogonServer = objWshShell.ExpandEnvironmentStrings("%Logonserver%")
  54. vaSessionData(6)=strLogonServer
  55.  
  56. 'Get IP addresses from all DHCPd interfaces.
  57. strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE MACAddress > ''"
  58.  
  59. Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
  60. Set colItems      = objWMIService.ExecQuery( strQuery, "WQL", 48 )
  61.  
  62. For Each objItem In colItems
  63.     If IsArray( objItem.IPAddress ) Then
  64.         If UBound( objItem.IPAddress ) = 0 Then
  65.             strIP = "IP Address: " & objItem.IPAddress(0)
  66.         Else
  67.             strIP = Join( objItem.IPAddress, "," )
  68.         End If
  69.     End If
  70. Next
  71.  
  72. vaSessionData(7)="""" & strIP & """"
  73.  
  74.  
  75. 'Get some useful local computer information
  76. strComputer = "."
  77. Set colSettings = objWMIService.ExecQuery _
  78.     ("Select * from Win32_ComputerSystem")
  79. For Each objComputer in colSettings
  80.     vaSessionData(8)=objComputer.Name
  81.     vaSessionData(9)=objComputer.Manufacturer
  82.     vaSessionData(10)=objComputer.Model
  83. Next
  84. Set objWMIService = GetObject("winmgmts:" _
  85.     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  86. Set colSettings = objWMIService.ExecQuery _
  87.     ("Select * from Win32_OperatingSystem")
  88. For Each objOperatingSystem in colSettings
  89.     vaSessionData(11)=objOperatingSystem.Version
  90.     vaSessionData(12)=objOperatingSystem.ServicePackMajorVersion & "." & objOperatingSystem.ServicePackMinorVersion
  91.     vaSessionData(13)=objOperatingSystem.FreePhysicalMemory
  92. Next
  93.  
  94. strComputer = "."
  95. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  96. Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
  97. For Each objItem in colItems
  98.     vaSessionData(14)=objItem.LoadPercentage
  99.     vaSessionData(15)="""" & objItem.Name & """"
  100. Next
  101.  
  102. strComputer = "." ' Local computer
  103.  
  104. set objWMIDateTime = CreateObject("WbemScripting.SWbemDateTime")
  105. set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  106. set colOS = objWMI.InstancesOf("Win32_OperatingSystem")
  107. for each objOS in colOS
  108.     objWMIDateTime.Value = objOS.LastBootUpTime
  109.     vaSessionData(16)=objWMIDateTime.GetVarDate
  110.     vaSessionData(17)=TimeSpan(objWMIDateTime.GetVarDate,Now)
  111. next
  112.  
  113. Function TimeSpan(dt1, dt2)
  114.     ' Function to display the difference between
  115.    ' 2 dates in hh:mm:ss format
  116.    If (isDate(dt1) And IsDate(dt2)) = false Then
  117.         TimeSpan = "00:00:00"
  118.         Exit Function
  119.         End If
  120.  
  121.         seconds = Abs(DateDiff("S", dt1, dt2))
  122.         minutes = seconds \ 60
  123.         hours = minutes \ 60
  124.         minutes = minutes mod 60
  125.         seconds = seconds mod 60
  126.  
  127.         if len(hours) = 1 then hours = "0" & hours
  128.  
  129.         TimeSpan = hours & ":" & _
  130.             RIGHT("00" & minutes, 2) & ":" & _
  131.             RIGHT("00" & seconds, 2)
  132. End Function
  133.  
  134. JoinedArray=(join(vaSessionData,","))
  135.  
  136. 'Write our to file in users temp dir.
  137. Dim objFileSystem, objOutputFile, objOutputFile2
  138. Dim strOutputFile
  139. Dim strOutputFile2
  140.  
  141. Set objTemp = WScript.CreateObject("Scripting.FileSystemObject").GetSpecialFolder(2)
  142. strOutputFile = objTemp & "\Session_Info.log"
  143. strOutputFile2 = objTemp & "\Logon_Time.tmp"
  144.  
  145. Set objFileSystem = CreateObject("Scripting.fileSystemObject")
  146. Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)
  147. Set objOutputFile2 = objFileSystem.CreateTextFile(strOutputFile2, TRUE)
  148.  
  149. objOutputFile.WriteLine (JoinedArray)
  150. objOutputFile.Close
  151.  
  152. objOutputFile2.WriteLine (Date & " " & Time)
  153. objOutputFile2.Close
  154.  
  155. Set objFileSystem = Nothing
  156.  
  157. 'Wscript.Echo "DONE!"
  158.  
  159. WScript.Quit(0)
RAW Paste Data
Top