code_junkie

Determining how long the user is logged on to Windows

Nov 10th, 2011
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. strComputer = "."
  2. Set objWMIService = GetObject("winmgmts:" _
  3. & "{impersonationLevel=impersonate}!\" _
  4. & strComputer & "rootcimv2")
  5. Set sessions = objWMIService.ExecQuery _
  6. ("select * from Win32_Session")
  7.  
  8. For Each objSession in sessions
  9. Wscript.Echo objSession.StartTime
  10. Next
  11.  
  12. Set logins = objWMIService.ExecQuery _
  13. ("select * from Win32_NetworkLoginProfile")
  14. For Each objSession in logins
  15. Wscript.Echo objSession.LastLogon
  16. Next
Add Comment
Please, Sign In to add comment