[python-win32] pywin32 question

Steven Manross steven at manross.net
Sun Mar 13 11:26:11 EDT 2022


While I don’t have a huge environment to test in, this seems to work remotely from my win 10 pc to my Windows Server 2016 which has remote admin RDP enabled…  I would assume it’s the same APIs to talk to a full fledged WTS Server.

Kudos to the internet for having the answer already written down for me…  even if it was in python 2 syntax (what else should I expect from a post in 11/2007?).  😊

https://mail.python.org/pipermail/python-win32/2007-November/006425.html

import win32ts

for s in win32ts.WTSEnumerateSessions(win32ts.WTSOpenServer("MYSERVER.MYDOMAIN.COM"),1):
    if s['State'] == win32ts.WTSActive:
        print(f"Session is active: {s}")

output:

Session is active: {'SessionId': 1, 'WinStationName': 'RDP-Tcp#124', 'State': 0}

take a look at win32ts here:

http://timgolden.me.uk/pywin32-docs/win32ts.html

I am guessing you would also want to use “WTSQuerySessionInformation” as well to get more detailed information about the session, but I will leave that to you to explore.

I just found this today, so I am no expert on use of this module but it looks GREAT and I will likely develop something with it myself eventually.

Steven
From: python-win32 <python-win32-bounces+steven=manross.net at python.org> On Behalf Of Craig R. Matthews
Sent: Saturday, March 12, 2022 12:02 AM
To: python-win32 at python.org
Subject: [python-win32] pywin32 question

I was wondering if there is a way in python to determine the idle time for a terminal server session as QUERY USER does.

Also, is there a way to get that python code to run for a server other than the one running the code (as in QUERY USER /SERVER:name)?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/python-win32/attachments/20220313/16fa6aa1/attachment.html>


More information about the python-win32 mailing list