Questions tagged [wtsapi32]

For questions about how to use Windows Terminal Services (WTS) API functions (named WTS*), declared in wtsapi32.h / wtsapi32.lib.

Windows Terminal Services (WTS) API functions (named WTS*), declared in wtsapi32.h / wtsapi32.lib, provide a mechanism for querying and manipulating Windows Remote Desktop sessions. Since the underlying WTS session mechanism is also used for local sessions, these APIs can also be used to inquire about and modify local Windows GUI sessions, including those used for Fast User Switching. See also Microsoft's documentation

27 questions
7
votes
1 answer

How can I get the current user token for the physical session?

I have some code, with which I'm trying to get the current session user token: #include DWORD activeSessionId = WTSGetActiveConsoleSessionId(); HANDLE currentToken; BOOL queryRet = WTSQueryUserToken(activeSessionId,…
Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
6
votes
3 answers

What makes SwitchDesktop not work right after a user unlocks it session?

I have a program that switches desktop and start a new process on it. When the process exits, the parent process restores the original desktop. For testing purposes, I put a button in a plain win32 app that triggers the switch. It works, and closing…
ixe013
  • 9,559
  • 3
  • 46
  • 77
4
votes
4 answers

WTSQuerySessionInformation returning empty strings

I've written a program which should query the Terminal Services API and print out some state information about the sessions running on a terminal services box. I'm using the WTSQuerySessionInformation function to do this and it's returning some…
Benj
  • 31,668
  • 17
  • 78
  • 127
2
votes
0 answers

WTSSendMessage on modern Windows Server

I'm writing a code for customized management of remote desktop sessions, similar to RD service manager from Windows Server. I'm using functions from wtsapi32.dll and winsta.dll to enumerate sessions, get session information, disconnect/logoff users…
Aloraman
  • 1,389
  • 1
  • 21
  • 32
2
votes
1 answer

WTSConnectSession

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…
kspeckhals
  • 31
  • 3
1
vote
1 answer

WTS LastInputTime

i'm trying to retrive the difference between CurrentTime and LastInputTime and comparing it to another value. CurrentTime is updating correctly but LastInputTime is always a constant value, i dont know why sometimes is 0 , sometimes is other…
dcasda
  • 13
  • 4
1
vote
1 answer

Query with wtsapi32.dll doesn`t work with SAM-Account-Name for japanese users

I am working with wtsapi32.dll. (Window Terminal Service api) I am trying to get user info from method WTSQueryUserConfig. [DllImport("wtsapi32.dll", CharSet = CharSet.Ansi, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private…
Ivan Rodriguez
  • 426
  • 4
  • 14
1
vote
1 answer

Is it possible to capture the local user (not the remote user) within a RDP Session

I am trying to capture the local user name from a RDP Session. To clarify, see below example: My local workstation is call WORKSTATION1, I’m logged in to this local workstation as JOHN.DOE. I make an RDP connection to work using JANE.DOE. Is it…
Matt C
  • 21
  • 1
1
vote
0 answers

How to check if a station is locked using powershell

I understand that it is possible to check the state of a computer using wtsapi32.dll using c#. but is it possible to do that using powershell?
Falah Abu Hassan
  • 105
  • 2
  • 11
0
votes
0 answers

I'm trying to get all the running processes on my PC using WTSEnumerateProcesses

I'm trying to use the WTSEnumerateProcesses() function in a project to get all the processes. Here is my code #include #include #include #include #pragma comment(lib, "Wtsapi32.lib") using namespace…
spookyss
  • 27
  • 6
0
votes
0 answers

WTSQueryUser Token returning Error code: 1314

I want to fetch an access token of a logged in user using WTSQueryUserToken(), but it returns error code: 1314. My code for reference: DWORD sessionId = -1; DWORD sessionCount = 0; WTS_SESSION_INFOW* pSession = NULL; if…
0
votes
2 answers

Why does WTSFreeMemoryExA always return ERROR_INVALID_PARAMETER when passed a WTSTypeClass of WTSTypeSessionInfoLevel1?

According to the documentation, WTSFreeMemoryExA can be used to free a WTS_SESSION_INFO_1A structure by passing a WTS_TYPE_CLASS of WTSTypeSessionInfoLevel1. However, any attempt to do so fails with error code 87 (ERROR_INVALID_PARAMETER, "The…
Simon Kissane
  • 4,373
  • 3
  • 34
  • 59
0
votes
0 answers

Create Remote Desktop Services Child sessions

I am trying to create a remote desktop child session. I can successfully create one on my laptop. I tried on AWS with Windows Server 2016 Datacenter and it was failing. Calls to WTSEnableChildSessions and WTSIsChildSessionsEnabled returned false.…
Raj
  • 1
  • 1
0
votes
1 answer

Trying to enumerate Terminal Server sessions produces AccessViolationException (.NET and Native DLL)

I am trying to enumerate all remote desktop sessions in C# using the function WtsEnumerateSessionsExA defined in WtsApi32.dll. This function writes into an array of WTS_SESSION_INFO_1A structs whose pointer is passed as a parameter. You can find the…
PauMAVA
  • 1,163
  • 14
  • 23
0
votes
0 answers

How to implement WTSRegisterSessionNotification function

I want to implement WTSRegisterSessionNotification function for my project and now I'm stuck with HINSTANCE hInstance; I want an coding example how to implement HINSTANCE in c++ #include #include #include #include…
Muhammad Bin Ali
  • 205
  • 2
  • 13
1
2