From ad3a991202d5d352488218d3419d03768c5a787e Mon Sep 17 00:00:00 2001 From: petur-keystrike <148981503+petur-keystrike@users.noreply.github.com> Date: Fri, 18 Oct 2024 02:49:41 +0000 Subject: [PATCH] Add support for WTSIsRemoteSession flag. (#2152) When WTSIsRemoteSession is passed to WTSQuerySessionInformation, it returns a single byte containing the return value. --- win32/src/win32tsmodule.cpp | 4 ++++ win32/test/test_win32ts.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 win32/test/test_win32ts.py diff --git a/win32/src/win32tsmodule.cpp b/win32/src/win32tsmodule.cpp index c4156f9f5f..ddd383dee0 100644 --- a/win32/src/win32tsmodule.cpp +++ b/win32/src/win32tsmodule.cpp @@ -409,6 +409,9 @@ static PyObject *PyWTSQuerySessionInformation(PyObject *self, PyObject *args, Py case WTSConnectState: // @flag WTSConnectState|Int, from WTS_CONNECTSTATE_CLASS ret = PyLong_FromLong(*(INT *)buf); break; + case WTSIsRemoteSession: // @flag WTSIsRemoteSession|Boolean + ret = PyBool_FromLong(*(BYTE *)buf); + break; case WTSClientDisplay: { // @flag WTSClientDisplay|Dict containing client's display settings WTS_CLIENT_DISPLAY *wcd = (WTS_CLIENT_DISPLAY *)buf; ret = Py_BuildValue("{s:k, s:k, s:k}", "HorizontalResolution", wcd->HorizontalResolution, @@ -768,6 +771,7 @@ PYWIN_MODULE_INIT_FUNC(win32ts) PyModule_AddIntConstant(module, "WTSClientAddress", WTSClientAddress); PyModule_AddIntConstant(module, "WTSClientDisplay", WTSClientDisplay); PyModule_AddIntConstant(module, "WTSClientProtocolType", WTSClientProtocolType); + PyModule_AddIntConstant(module, "WTSIsRemoteSession", WTSIsRemoteSession); // WTS_CONFIG_CLASS PyModule_AddIntConstant(module, "WTSUserConfigInitialProgram", WTSUserConfigInitialProgram); diff --git a/win32/test/test_win32ts.py b/win32/test/test_win32ts.py new file mode 100644 index 0000000000..712b99272c --- /dev/null +++ b/win32/test/test_win32ts.py @@ -0,0 +1,19 @@ +# Tests for win32ts module + +import unittest + +import win32ts + + +class Win32TsTestCase(unittest.TestCase): + def test_is_remote_session(self): + ret = win32ts.WTSQuerySessionInformation( + win32ts.WTS_CURRENT_SERVER_HANDLE, + win32ts.WTS_CURRENT_SESSION, + win32ts.WTSIsRemoteSession, + ) + self.assertIsInstance(ret, bool) + + +if __name__ == "__main__": + unittest.main()