def reListSessions(outFh):
    protocols = {
        ts.WTS_PROTOCOL_TYPE_CONSOLE: "console",
        ts.WTS_PROTOCOL_TYPE_ICA: "citrix",
        ts.WTS_PROTOCOL_TYPE_RDP: "rdp",
    }

    #hostname = api.GetComputerName()
    hserver = ts.WTS_CURRENT_SERVER_HANDLE

    currentSessId = ts.WTSGetActiveConsoleSessionId()

    format = "%(user)-16s %(active)1s%(session)-7s %(id)-7s %(protocol)-8s"
    print >> outFh, format % dict(
        user = "USER",
        active = "",
        session = "SESSION",
        id = "ID",
        protocol = "PROTOCOL",
    )

    for session in ts.WTSEnumerateSessions(hserver):
        sessionId = session["SessionId"]
        session["User"] = ts.WTSQuerySessionInformation(hserver, sessionId, ts.WTSUserName)
        #session["Address"] = ts.WTSQuerySessionInformation(hserver, sessionId, ts.WTSClientAddress)
        session["Protocol"] = ts.WTSQuerySessionInformation(hserver, sessionId, ts.WTSClientProtocolType)
        print >> outFh, format % dict(
            user = session["User"] or "(none)",
            session = session["WinStationName"],
            id = session["SessionId"] % "(%d)",
            active = "*" if sessionId == currentSessId else "",
            protocol = protocols[session["Protocol"]],
        )
dataset/ETHPy150Open grawity/hacks/hacks/Dead-projects/Win32/fingerd.py/reListSessions/swapped operands of `%`