OVH Cloud OVH Cloud

[WINDEV 55] WTSQuerySessionInformationA

2 réponses
Avatar
Xavier ROUQUIER
Avis aux experts des API,
je cherche quelqu'un qui peut m'écrire un bou de code, pour récupérer l'id
de ma session TSE grace à WTSQuerySessionInformationA

en windev 55

petit lien sur la doc :
http://msdn.microsoft.com/library/en-us/termserv/termserv/wtsquerysessioninf
ormation.asp

merci d'avance

Xavier

2 réponses

Avatar
Peter
Xavier ROUQUIER wrote:

je cherche quelqu'un qui peut m'écrire un bou de code, pour récupérer l'id
de ma session TSE grace à WTSQuerySessionInformationA

en windev 55





WD75:
(dirty copy & paste, should work in wd55 with some change, int > long
int , API > CallDLL32 ..., & not exactly what you've asked for but...)
****

WTS_SESSION_INFO is structure
SessionId is int
pWinStationName is int
//state As WTS_CONNECTSTATE_CLASS
state is int
END

arrSessionStates is array fixed of 10 string
arrSessionStates[1]="Active"
arrSessionStates[2]="Connected"
arrSessionStates[3]="Query"
arrSessionStates[4]="Shadow"
arrSessionStates[5]="Disconnected"
arrSessionStates[6]="Idle"
arrSessionStates[7]="Listen"
arrSessionStates[8]="Reset"
arrSessionStates[9]="Down"
arrSessionStates[10]="Initialize"

liDLLHandle, hServer are int
pCount , p, p1, pBytes, retval, i, j are int
fsWinStationName is ASCIIZ string on 128
fsUserName is ASCIIZ string on 260
dynarrSessionInfo is array dynamic of 1 WTS_SESSION_INFO
ServerName is ASCIIZ string on 257

liDLLHandle = LoadDLL("WTSAPI32")
IF liDLLHandle > 0 THEN
ServerName="server"
hServer=API("WTSAPI32","WTSOpenServerA",&ServerName)
//hServer=API("WTSAPI32","WTSOpenServerA",WTS_CURRENT_SERVER_HANDLE)
Multitask(10)
IF hServer>0 THEN
retval=API("WTSAPI32","WTSEnumerateSessionsA",hServer,0,1,&p,&pCount)
IF NOT retval RETURN
IF pCount>0 THEN
Dimension(dynarrSessionInfo,pCount) //redim array of WTS_SESSION_INFO
structures
Transfer(&dynarrSessionInfo,p,12*pCount) //12 = size of 1
WTS_SESSION_INFO structure
END

API("WTSAPI32","WTSFreeMemory",p)

FOR i = 1 TO pCount

retval=API("WTSAPI32","WTSQuerySessionInformationA",hServer,dynarrSessionInfo[i]:SessionID,6,&p1,&pBytes)
//6= WTSWinStationName
fsWinStationName=""
IF retval THEN
IF pBytes>0 THEN
Transfer(&fsWinStationName,p1,pBytes)
END
API("WTSAPI32","WTSFreeMemory",p1)
p1=0
END

TableAddLine(Table1,dynarrSessionInfo[i]:SessionID,fsWinStationName,arrSessionStates[dynarrSessionInfo[i]:State
+ 1])
END
END
API("WTSAPI32","WTSCloseServer",hServer)
END
FreeDLL(liDLLHandle)
***

--
Peter
Avatar
Xavier ROUQUIER
Ok, thx !!

voici mon code au final :

p1, pBytes, retval are entier long
fsWinStationName is ASCIIZ string on 128
ServerName is ASCIIZ string on 257
ServerName=NetNomMachine()
hServer est un entier long AppelDll32("WTSAPI32","WTSOpenServerA",&ServerName)
Multitask(1)
_dll est un entier long = chargedll("wtsapi32")
SI _dll ALORS
IF hServer THEN
retval=AppelDll32("WTSAPI32","WTSQuerySessionInformationA",hServer,-1,6,&p
1,&pBytes)
IF retval THEN
IF pBytes>0 THEN
Transfer(&fsWinStationName,p1,pBytes)
END
AppelDll32("WTSAPI32","WTSFreeMemory",p1)
p1=0
END
AppelDll32("WTSAPI32","WTSCloseServer",hServer)
END
FIN
dechargedll(_dll)
trace(fsWinStationName)


"Peter" a écrit dans le
message de news: 40e3cf5b$0$57544$
Xavier ROUQUIER wrote:

> je cherche quelqu'un qui peut m'écrire un bou de code, pour récupérer


l'id
> de ma session TSE grace à WTSQuerySessionInformationA
>
> en windev 55
>


WD75:
(dirty copy & paste, should work in wd55 with some change, int > long
int , API > CallDLL32 ..., & not exactly what you've asked for but...)
****

WTS_SESSION_INFO is structure
SessionId is int
pWinStationName is int
file://state As WTS_CONNECTSTATE_CLASS
state is int
END

arrSessionStates is array fixed of 10 string
arrSessionStates[1]="Active"
arrSessionStates[2]="Connected"
arrSessionStates[3]="Query"
arrSessionStates[4]="Shadow"
arrSessionStates[5]="Disconnected"
arrSessionStates[6]="Idle"
arrSessionStates[7]="Listen"
arrSessionStates[8]="Reset"
arrSessionStates[9]="Down"
arrSessionStates[10]="Initialize"

liDLLHandle, hServer are int
pCount , p, p1, pBytes, retval, i, j are int
fsWinStationName is ASCIIZ string on 128
fsUserName is ASCIIZ string on 260
dynarrSessionInfo is array dynamic of 1 WTS_SESSION_INFO
ServerName is ASCIIZ string on 257

liDLLHandle = LoadDLL("WTSAPI32")
IF liDLLHandle > 0 THEN
ServerName="server"
hServer=API("WTSAPI32","WTSOpenServerA",&ServerName)
file://hServer=API("WTSAPI32","WTSOpenServerA",WTS_CURRENT_SERVER_HANDLE)
Multitask(10)
IF hServer>0 THEN
retval=API("WTSAPI32","WTSEnumerateSessionsA",hServer,0,1,&p,&pCount)
IF NOT retval RETURN
IF pCount>0 THEN
Dimension(dynarrSessionInfo,pCount) file://redim array of WTS_SESSION_INFO
structures
Transfer(&dynarrSessionInfo,p,12*pCount) file://12 = size of 1
WTS_SESSION_INFO structure
END

API("WTSAPI32","WTSFreeMemory",p)

FOR i = 1 TO pCount




retval=API("WTSAPI32","WTSQuerySessionInformationA",hServer,dynarrSessionInf
o[i]:SessionID,6,&p1,&pBytes)
file://6= WTSWinStationName
fsWinStationName=""
IF retval THEN
IF pBytes>0 THEN
Transfer(&fsWinStationName,p1,pBytes)
END
API("WTSAPI32","WTSFreeMemory",p1)
p1=0
END




TableAddLine(Table1,dynarrSessionInfo[i]:SessionID,fsWinStationName,arrSessi
onStates[dynarrSessionInfo[i]:State
+ 1])
END
END
API("WTSAPI32","WTSCloseServer",hServer)
END
FreeDLL(liDLLHandle)
***

--
Peter