Bonjour,
J'essaie de récupérer les différentes informations d'une session WTS et je butte sur la reprise d'informations au niveau des pointeurs.
Je m'explique :
Via la dll wtsapi32, il est possible de récupérer les informations d'une session :
où WTS_INFO_CLASS est définie de la façon suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 [DllImport("wtsapi32", CharSet=CharSet.Auto)] static extern Boolean WTSQuerySessionInformation(IntPtr hServer, Int32 SessionId, WTS_INFO_CLASS InfoClass, ref IntPtr ppBuffer, ref Int32 pCount);
Pour faire un test, je lance donc sur la session courante du serveur courant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 public enum WTS_INFO_CLASS { WTSInitialProgram = 0, WTSApplicationName = 1, WTSWorkingDirectory = 2, WTSOEMId = 3, WTSSessionId = 4, WTSUserName = 5, WTSWinStationName = 6, WTSDomainName = 7, WTSConnectState = 8, WTSClientBuildNumber = 9, WTSClientName = 10, WTSClientDirectory = 11, WTSClientProductId = 12, WTSClientHardwareId = 13, WTSClientAddress = 14, WTSClientDisplay = 15, WTSClientProtocolType = 16, WTSIdleTime = 17, WTSLogonTime = 18, WTSIncomingBytes = 19, WTSOutgoingBytes = 20, WTSIncomingFrames = 21, WTSOutgoingFrames = 22, };
Pour voir les types, voir msdn http://msdn2.microsoft.com/en-us/library/aa383861.aspx
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 WTSQuerySessionInformation(IntPtr.Zero, -1, WTSInfoClassType, ref Buffer, ref bytesReturned);
Pour reprendre les champs de type string, pas de problème :
Pour les champs de type structure (ClientDisplay et ClientAdress), pas de problème :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 System.Runtime.InteropServices.Marshal.PtrToStringAuto(Buffer);
Mais comment faire pour les autres types (Ulong et Ushort) ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 if (WTSInfoClassType == WTS_INFO_CLASS.WTSClientAddress) { WtsClientAddress WtsCa = (WtsClientAddress)Marshal.PtrToStructure(Buffer, typeof(WtsClientAddress)); return WtsCa.Address[2].ToString() + "." + WtsCa.Address[3].ToString() + "." + WtsCa.Address[4].ToString() + "." + WtsCa.Address[5].ToString(); } if (WTSInfoClassType == WTS_INFO_CLASS.WTSClientDisplay) { WtsClientDisplay WtsCd = (WtsClientDisplay)Marshal.PtrToStructure(Buffer, typeof(WtsClientDisplay)); return "HorizontalResolution" + WtsCd.HorizontalResolution.ToString()+" | VerticalResolution : " + WtsCd.VerticalResolution.ToString() + " | ColorDepth : " + WtsCd.ColorDepth.ToString(); }
Je vous remercie d'avance pour l'aide que vous pourrez m'apporter.
Partager