Returns information about logon sessions associated with the user currently logged on to a computer.

This script was tested using Python 2.2.2-224 for Microsoft Windows, available from ActiveState.

Python
Edit|Remove
import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_LogonSession")
for objItem in colItems:
    print "Authentication Package: ", objItem.AuthenticationPackage
    print "Caption: ", objItem.Caption
    print "Description: ", objItem.Description
    print "Install Date: ", objItem.InstallDate
    print "Logon Id: ", objItem.LogonId
    print "Logon Type: ", objItem.LogonType
    print "Name: ", objItem.Name
    print "Start Time: ", objItem.StartTime
    print "Status: ", objItem.Status