Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Terminal server WTSQuerySessionInformation DllCall example.wbt
;get session state using dll title = "Test DLL" dll_name = "M:\WTSRV\system32\WTSAPI32.DLL" ;dll_name = "M:\WTSRV\system32\KERNEL32.DLL" dll_handle = DllLoad(dll_name) ;get seesion state ;BOOL WTSQuerySessionInformation( ; HANDLE hServer, ; DWORD SessionId, ; WTS_INFO_CLASS WTSInfoClass, ; LPTSTR *ppBuffer, ; DWORD *pBytesReturned ;); ;return_type = lptstr ep_name = "WTSQuerySessionInformationW" ;Maybe (?) A instead of W on the end? WTS_CURRENT_SERVER_HANDLE=0 ; from H file hServer = WTS_CURRENT_SERVER_HANDLE WTS_CURRENT_SESSION= -1 ; from H file SessionID = WTS_CURRENT_SESSION WTSConnectState=8 ;WTS_INFO_CLASS is a enumumeration., starting from zero, WTSConnectState is the 8th item WTSInfoClass = WTSConnectState ; and it is a LONG like most everthing else ppBuffer=BinaryAlloc(4) ;Allocate buffer for return pointer BinaryEODSet(ppBuffer,4) ;tell WinBatch all data is valid pBytesReturned=BinaryAlloc(4) ;Allocate buffer for return count BinaryEODSet(pBytesReturned,4) ;Tell WInbatch all data is valid ;The DLL Call flag = DllCall(dll_handle, long:ep_name, LONG:hServer, long:SessionID, LONG:WTSInfoClass, lpbinary:ppBuffer,lpbinary:pBytesReturned) ;flag return value just indicates success/failure ofthe function if flag==0 ; if flag==0 DllCall worked. Function failed. BinaryFree(ppbuffer) BinaryFree(pBytesReturned) Message("Eeeek","Function failed") exit endif BytesReturned=BinaryPeek4(pBytesReturned,0) Pointer2Buffer=BinaryPeek4(ppBuffer,0) BinaryFree(pBytesReturned) BinaryFree(ppBuffer) If BytesReturned!=4 Message("Eeek","pBytesReturned is %pBytesReturned% instead of 4") exit endif ;Oh wonderful We have a pointer to some obscure INT someplace in memory ;Look it up session_state=IntControl(32,Pointer2Buffer,"LONG",0,0) ;Free the buffer. Anotehr wonderful DLLCall DllCall(dll_handle,void:"WTSFreeMemory",LONG:Pointer2Buffer) ;DOne with DLL DllFree(dll_handle) ;typedef enum _WTS_CONNECTSTATE_CLASS { state0 = "Active" ;0 WTSActive, // User logged on to WinStation state1 = "Connected" ;1 WTSConnected, // WinStation connected to client state2 = "Connection in process" ;2 WTSConnectQuery, // In the process of connecting to client state3 = "Shadowing" ;3 WTSShadow, // Shadowing another WinStation state4 = "Disconnected" ;4 WTSDisconnected, // WinStation logged on without client state5 = "Waiting" ;5 WTSIdle, // Waiting for client to connect state6 = "Listening" ;6 WTSListen, // WinStation is listening for connection state7 = "Being reset" ;7 WTSReset, // WinStation is being reset state8 = "Down - Error" ;8 WTSDown, // WinStation is down due to error state9 = "Initializing" ;9 WTSInit, // WinStation in initialization ;} WTS_CONNECTSTATE_CLASS; Message(title, state%session_state%) -------------------------------------------
Article ID: W14897
File Created: 2011:11:09:09:21:48
Last Updated: 2011:11:09:09:21:48