Click here to Skip to main content
15,742,226 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have a window service and I use it to launch my another application. this is working fine when ther is a single user logged into server. but when multiple users are logged in on server(jump server) then that application is getting opened in the session of user who has first logged in to server.

I am using ProcessExtension class and finding currently logged in user and then launching my application from window service.

I want from which user's session the call came so that ill be able to launch my application in that session.

Thank you in advance.

What I have tried:

from below code I am able to get currently logged in users but it does not giving me which exact user.

if (WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, ref pSessionInfo, ref sessionCount) != 0)
                var arrayElementSize = Marshal.SizeOf(typeof(WTS_SESSION_INFO));
                writeLog("arrayElementSize : " + arrayElementSize);
                var current = pSessionInfo;

                for (var i = 0; i < sessionCount; i++)
                    var si = (WTS_SESSION_INFO)Marshal.PtrToStructure((IntPtr)current, typeof(WTS_SESSION_INFO));
                    current += arrayElementSize;

                    if (si.State == WTS_CONNECTSTATE_CLASS.WTSActive)
                        activeSessionId = si.SessionID;
Updated 28-May-20 23:22pm

1 solution

Share this answer
Param From Mumbai 1-Jun-20 12:22pm    
Thank you for your reply.
I have tried using class mentioned in your link but still same. I think the problem is that WTSEnumerateSessions functions returns all the logged in user but it is not able to give which user excuting this process.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900