2

I am trying to use this function to connect to a specific user session. I have tried everything and the function always fails with either ERROR_ACCESS_DENIED 5 (0x5) Access is denied or ERROR_CTX_WINSTATION_ACCESS_DENIED 7045 (0x1B85) The requested session access is denied. Even hard-coding the session ID in and the password like this

WTSConnectSession(2, 1 ,TEXT("test1"),false);

Is there a better way to start a user session than to use this function. I am trying to implement Fast User Switching and this is the last piece in the puzzle is to logon a user session. Thank you.

rkosegi
  • 14,165
  • 5
  • 50
  • 83
kspeckhals
  • 31
  • 3
  • Did you ever figure this out? I'm trying to do something similar and struggling to find good information. – LorneCash Mar 24 '18 at 04:52

1 Answers1

1

Are sure that you are connecting with username (specified by TargetLogonId parameter) in "Remote Desktop Users" group?

You can check it using

net localgroup "Remote Desktop users"

Another option is to enable security auditing and analyzing security event log. It will tells you exact root cause of ERROR_CTX_WINSTATION_ACCESS_DENIED

0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
rkosegi
  • 14,165
  • 5
  • 50
  • 83
  • I added all the users to "Remote Desktop Users" group, and still nothing. Maybe a little clarification as to what I am exactly trying to accomplish. So I am trying to implement a custom credential provider, so when a user leaves the area I disconnect the session they are logged into and when that user approaches I want to open or just connect to the that users specific session. I thought that `WTSConnectSession()` would work but now I am second guessing it. Has anybody had to do anything similar? – kspeckhals Jun 04 '12 at 20:43