• Welcome to Theos PowerBasic Museum 2017.

Does anyone have experience of WTSGetActiveConsoleSessionID

Started by Mike Charnock, January 30, 2011, 02:03:10 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mike Charnock

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

José Roca

Your declare is missing the alias clause. This is the correct declare:


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


Mike Charnock

Thanks José, How could I have missed that - obviously been looking at it for too long.