Theos PowerBasic Museum 2017

Archive => Discussion - Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Topic started by: Mike Charnock on January 30, 2011, 02:03:10 AM

Title: Does anyone have experience of WTSGetActiveConsoleSessionID
Post by: Mike Charnock on January 30, 2011, 02:03:10 AM
I'm trying to start a process on the logged in session from a Service under Windows 7.

Since Vista the services still operate in Session 0 (with no GUI) but the logged in users have been moved to other sessions (part of the vista security fixes).

In order to run a process in a logged in session the procedure is to use WTSEnumerateSessions, and WTSQuerySessionInformation to get the session ID, and then WTSQueryUserToken to get the user token. From there you can use the user token in the CreateProcessAsUser Win32 API.

This method is useful because you don't need to know the logged in user's username/password so long as you are running as a service running as local system account.

As I want to start my process in the console session I should be able to get the current console session id via WTSGetActiveConsoleSessionId (rather than WTSEnumerateSessions, and WTSQuerySessionInformation)

The problem - I can't find a declaration (or any examples) for this.

I have tried DECLARE FUNCTION WTSGetActiveConsoleSessionID  LIB "Kernel32.dll" () AS LONG, but get "The procedure entry point WTSGetActiveConsoleSessionID could not be located in the dynamic link library KERNEL32.DLL" when I try to install my service that uses the call.

Does anyone have any ideas - I think getting a solution to this (running procs in user sessions from services on recent OSs) would be generally useful - as well as helping me out in this instance.

Thanks to all in advance.

Mike
Title: Re: Does anyone have experience of WTSGetActiveConsoleSessionID
Post by: José Roca on January 30, 2011, 03:03:15 AM
Your declare is missing the alias clause. This is the correct declare:


DECLARE FUNCTION WTSGetActiveConsoleSessionId LIB "KERNEL32.DLL" ALIAS "WTSGetActiveConsoleSessionId" () AS DWORD

Title: Re: Does anyone have experience of WTSGetActiveConsoleSessionID
Post by: Mike Charnock on January 31, 2011, 12:05:14 AM
Thanks José, How could I have missed that - obviously been looking at it for too long.