OVH Cloud OVH Cloud

session "repliée"

14 réponses
Avatar
bayosky
bonjour,

avec Xp, un utilisateur A peut "replier sa session" et revenir à
l'écran d'accueil et permettre à un autre utilisateur B d'utiliser une
autre session. Les appli lancées par A restent alors actives...
J'aimerais savoir si ce "repliage" de session est un événement
détectable par un programme qui tourne... sous la session de A


Merci d'avance,

HB

10 réponses

1 2
Avatar
Bayosky
Dans le message ,
bayosky a écrit :

bonjour,

plus précisément :

Est-ce qq part dans la machine ( BdR, ?) un programme peut trouver l'info
suivante :
est que je ( le programme ) tourne dans une session "repliée" ou non ...

J'ai regardé ce qui se passe quand plusieurs sessions sont ouvertes et que
l'on bascule de l'une à l'autre mais je n'ai nulle part vu l'info simple :
session actuellement active : utilisateur Toto

à moins que HKCU ne soit pas contextuel et que, d'une session "repliée" cela
donne la ruche de la session réellement active ....
je n'ai pas testé ...

Qui sait tout ça ?

Hubert.
Avatar
Clive Lumb
"bayosky" a écrit dans le message de
news:
bonjour,

avec Xp, un utilisateur A peut "replier sa session" et revenir à
l'écran d'accueil et permettre à un autre utilisateur B d'utiliser une
autre session. Les appli lancées par A restent alors actives...
J'aimerais savoir si ce "repliage" de session est un événement
détectable par un programme qui tourne... sous la session de A


Merci d'avance,

HB




Trouvé ceci:
APIs for acquiring logon session information
The two APIs that allow for enumerating logon sessions and retrieving
information of logon sessions are LsaEnumerateLogonSessions and
LsaGetLogonSessionData. Both of them are implemented in secur32.dll and are
officially documented for Windows XP. Upon successful execution,
LsaEnumerateLogonSessions returns an array of locally unique IDs, or LUIDs,
to the caller. A LUID is a 64-bit integer value that is issued by the system
and that is guaranteed to be unique until the system is rebooted. This means
that no two logon sessions can have the same LUID unless the computer is
rebooted in between creation of the two logon sessions. In order to retrieve
information about the individual logon sessions, you can iterate over the
array of LUIDs returned by LsaEnumerateLogonSessions and pass each LUID to
LsaGetLogonSessionData. Upon success, LsaGetLogonSessionData creates a
SECURITY_LOGON_SESSION_DATA struct for the caller. This struct contains all
necessary information about that particular logon session, such as the LUID
itself, user name and logon domain, the authentication package used to
authenticate the user, the logon type (interactive, service, batch, or
network style), the Terminal Services session ID, the logon time, and the
SID of the user under whose auspices the logon session is running. One
particularly nice thing about these two APIs is that they also work on
Windows 2000, although they are only documented for XP.



ici: http://www.codeproject.com/system/logonsessions.asp
Avatar
Gloops
Clive Lumb a écrit, le 22/02/2006 10:39 :
ici: http://www.codeproject.com/system/logonsessions.asp



Merci du tuyau.

Il y a la mise en veille qui est un sujet proche, aussi.

Apparemment pour savoir si le système est actif c'est
GetSystemPowerStatus, donc en détectant un changement là-dessus on
devrait pouvoir savoir si on passe en veille ou si on en sort.
A tester.
ça on le trouve chez API-Guide.
Avatar
bayosky
Dans le message %,
Clive Lumb a écrit :


Bonjour,

C'est très gentil mais je ne vois rien de nettement en rapport avec
mon pb.
Il faut dire que ce long article en anglais n'est pas facile à
comprendre pour le bidouilleur médiocre que je suis...

Lorque la session est "repliée" elle est considérée comme active, les
processus ( même explorer;exe ) continuent de tourner et la "fenetre
du bureau" garde le statut "visible"
( j'ai vérifié avec GetDesktopWindow et IsWindowsVivible dans un prgm
tournant sous une session "repliée")
donc je cherche toujour quelle est la fonction qui me donnera une
réponse signalement ce changement d'état ...

A+

HB


Trouvé ceci:
APIs for acquiring logon session information
The two APIs that allow for enumerating logon sessions and
retrieving
information of logon sessions are LsaEnumerateLogonSessions and
LsaGetLogonSessionData. Both of them are implemented in secur32.dll
and are officially documented for Windows XP. Upon successful
execution, LsaEnumerateLogonSessions returns an array of locally
unique IDs, or LUIDs, to the caller. A LUID is a 64-bit integer
value
that is issued by the system and that is guaranteed to be unique
until the system is rebooted. This means that no two logon sessions
can have the same LUID unless the computer is rebooted in between
creation of the two logon sessions. In order to retrieve information
about the individual logon sessions, you can iterate over the array
of LUIDs returned by LsaEnumerateLogonSessions and pass each LUID to
LsaGetLogonSessionData. Upon success, LsaGetLogonSessionData creates
a SECURITY_LOGON_SESSION_DATA struct for the caller. This struct
contains all necessary information about that particular logon
session, such as the LUID itself, user name and logon domain, the
authentication package used to authenticate the user, the logon type
(interactive, service, batch, or network style), the Terminal
Services session ID, the logon time, and the SID of the user under
whose auspices the logon session is running. One particularly nice
thing about these two APIs is that they also work on Windows 2000,
although they are only documented for XP.



ici: http://www.codeproject.com/system/logonsessions.asp


Avatar
Clive Lumb
bayosky wrote:
Dans le message %,
Clive Lumb a écrit :


Bonjour,

C'est très gentil mais je ne vois rien de nettement en rapport avec
mon pb.
Il faut dire que ce long article en anglais n'est pas facile à
comprendre pour le bidouilleur médiocre que je suis...

Lorque la session est "repliée" elle est considérée comme active, les
processus ( même explorer;exe ) continuent de tourner et la "fenetre
du bureau" garde le statut "visible"
( j'ai vérifié avec GetDesktopWindow et IsWindowsVivible dans un prgm
tournant sous une session "repliée")
donc je cherche toujour quelle est la fonction qui me donnera une
réponse signalement ce changement d'état ...




5 minutes de recherche sur MSDN nous donne ceci :

Listening for Session Switch Events
Typically, an application does not need to be notified when a session switch
occurs. However, if the application needs to be aware when its desktop is
current, it can register for session switch notifications. Applications that
access the serial port or another shared resource on the computer should
check for this. To register for a notification, use the following function,
which can be found in Wtsapi32.h:

BOOL WINAPI
WTSRegisterSessionNotification(
HWND hWnd, // Window handle
DWORD dwFlags // Flags
);
The registered HWND receives the message WM_WTSSESSION_CHANGE.

In dwFlags you can specify:

a.. NOTIFY_FOR_THIS_SESSION. A window is notified only about the session
change events that affect the session to which window belongs.
b.. NOTIFY_FOR_ALL_SESSIONS. A window is notified for all session change
events.
The action happening on the session can be found in wParam code, which may
contain one of the following flags.

WTS_CONSOLE_CONNECT
WTS_CONSOLE_DISCONNECT
WTS_REMOTE_CONNECT
WTS_REMOTE_DISCONNECT
WTS_SESSION_LOGON
WTS_SESSION_LOGOFF
WTS_SESSION_LOCK
WTS_SESSION_UNLOCK
lParam contains the sessionId for the session affected.

When your process no longer requires these notifications or is terminating,
it should call the following to unregister its notification.

BOOL WINAPI
WTSUnRegisterSesssionNotification(
HWND hWnd // window handle.
);
The HWND values passed to WTSRegisterSessionNotification are reference
counted, so you must call WTSUnRegisterSessionNotification exactly the same
number of times that you call WTSRegisterSessionNotification.

Applications can use the WTS_CONSOLE_CONNECT, WTS_CONSOLE_DISCONNECT,
WTS_REMOTE_CONNECT, WTS_REMOTE_DISCONNECT messages to track their state, as
well as to release and acquire console specific resources.
Avatar
Guy DETIENNE
Salut ;O)

En suivant les infos de Clive Lumb, vois ici :
http://www.pellesoft.se/communicate/tips/tips.aspx?tid84

P.S: Il faudra aller sur le site vbaccelerator à
http://www.vbaccelerator.com/home/VB/Code/Libraries/Subclassing/SSubTimer/VB6_SSubTmr_Binary.asp
pour télécharger un petit truc et l'enregistrer pour faire fonctionner
l'exemple.

Guy



"bayosky" a écrit dans le message de
news:%23JOyZB%
Dans le message %,
Clive Lumb a écrit :


Bonjour,

C'est très gentil mais je ne vois rien de nettement en rapport avec
mon pb.
Il faut dire que ce long article en anglais n'est pas facile à
comprendre pour le bidouilleur médiocre que je suis...

Lorque la session est "repliée" elle est considérée comme active, les
processus ( même explorer;exe ) continuent de tourner et la "fenetre
du bureau" garde le statut "visible"
( j'ai vérifié avec GetDesktopWindow et IsWindowsVivible dans un prgm
tournant sous une session "repliée")
donc je cherche toujour quelle est la fonction qui me donnera une
réponse signalement ce changement d'état ...

A+

HB


> Trouvé ceci:
> APIs for acquiring logon session information
> The two APIs that allow for enumerating logon sessions and
> retrieving
> information of logon sessions are LsaEnumerateLogonSessions and
> LsaGetLogonSessionData. Both of them are implemented in secur32.dll
> and are officially documented for Windows XP. Upon successful
> execution, LsaEnumerateLogonSessions returns an array of locally
> unique IDs, or LUIDs, to the caller. A LUID is a 64-bit integer
> value
> that is issued by the system and that is guaranteed to be unique
> until the system is rebooted. This means that no two logon sessions
> can have the same LUID unless the computer is rebooted in between
> creation of the two logon sessions. In order to retrieve information
> about the individual logon sessions, you can iterate over the array
> of LUIDs returned by LsaEnumerateLogonSessions and pass each LUID to
> LsaGetLogonSessionData. Upon success, LsaGetLogonSessionData creates
> a SECURITY_LOGON_SESSION_DATA struct for the caller. This struct
> contains all necessary information about that particular logon
> session, such as the LUID itself, user name and logon domain, the
> authentication package used to authenticate the user, the logon type
> (interactive, service, batch, or network style), the Terminal
> Services session ID, the logon time, and the SID of the user under
> whose auspices the logon session is running. One particularly nice
> thing about these two APIs is that they also work on Windows 2000,
> although they are only documented for XP.
>
>
>
> ici: http://www.codeproject.com/system/logonsessions.asp



Avatar
Bayosky
Dans le message OWt5w%23%,
Guy DETIENNE a écrit :
Salut ;O)

En suivant les infos de Clive Lumb, vois ici :
http://www.pellesoft.se/communicate/tips/tips.aspx?tid84

P.S: Il faudra aller sur le site vbaccelerator à
http://www.vbaccelerator.com/home/VB/Code/Libraries/Subclassing/SSubTimer/VB6_SSubTmr_Binary.asp
pour télécharger un petit truc et l'enregistrer pour faire fonctionner
l'exemple.




Bon ,

J'ai téléchargé la dll et je j'ai enregistrée.
J'ai récupéré le code du site pellesoft.se . ça ressemble à ce que je
cherche mais il me reste qq questions pratiques, car la langue utilisée
m'est inconnue :o)

Visiblement il faut un "form" avec deux boutons ( en gardant les noms par
défaut )
J'ai donc sottement fait ça et j'ai mis l'ensemble du code au même niveau
( Form)

Quand on lance le truc ça se lance et ça attend sagement
mais si l'on clique sur l'un des boutons on obtient

runtime error 13 : Type mismatch
sur la ligne
DetachMessage Me, Me.hwnd, WM_WTSSESSION_CHANGE
( cas du bouton 2)
ou
AttachMessage Me, Me.hwnd, WM_WTSSESSION_CHANGE
( cas du bouton 1)

Il y a donc visiblement qqchose que je n'ai pas compris.

Merci d'avance,

cordialement,

HB
Avatar
Bayosky
Bon [soir/jour],

j'ai mis du temps mais j'ai compris,
du moins assez pour utiliser correctement ce truc.

voilà plus bas le code complet du "Form" nommé FORME
Il y a - un timer nommé Chrono
- un bouton Command1
- un label nommé Temps

L'effet obtenu est exactement ce qui me convient :
_______________________________________________________
Quand on lance l'éxécution, le label indique le temps qui passe
( départ à 00:00:00 )
Quand on "replie" la session sans la fermer le temps cesse d'être décompté

Quand on réouvre la session le décompte du temps reprend...
_______________________________________________________

Bien sûr ( rappel pour ceux qui n'ont pas suivi le fil)
il faut mettre SSubTmr6.dll dans System32
et l'enregistrer avec regsrv32 puis ajouter la référence au projet VB.

Seul défaut :
lors de la sortie ( sub Fin )
la détection d'erreur
provoque l'affichage du message "Opération réussie"
qui provient de MsgBox (GetError(Err.LastDllError))
Cela signifie que le test
If Not WTSUnRegisterSessionNotification(Me.hwnd)
n'est pas fiable :o)
donc pour la suite il faut "affiner" la detection d'erreur en sortie...
en éliminant le N° d'erreur qui correspond à la réussite.

Merci à tous,

Bien cordialement,

HB

------ Code ---------
Option Explicit
' ****************
Private Declare Function WTSRegisterSessionNotification Lib "Wtsapi32"
(ByVal hwnd As Long, ByVal THISSESS As Long) As Long
Private Declare Function WTSUnRegisterSessionNotification Lib "Wtsapi32"
(ByVal hwnd As Long) As Long
Private Declare Function GetLastError Lib "kernel32" () As Long
Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA"
(ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal
dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long,
Arguments As Long) As Long

Private Const NOTIFY_FOR_THIS_SESSION As Long = 0
Private Const WM_WTSSESSION_CHANGE As Long = &H2B1
Private Const WTS_SESSION_LOCK As Long = 7
Private Const WTS_SESSION_UNLOCK As Long = 8
Private Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Private Const LANG_NEUTRAL = &H0


Dim DEPART, RESTE As Date
' ****************
Implements ISubclass
' ****************
Private Sub Chrono_Timer()
RESTE = Time - DEPART
Temps.Caption = Format(RESTE, "hh:mm:ss")
End Sub
' ****************
Private Sub Command1_Click()
Fin
End Sub
' ****************
Private Property Let ISubclass_MsgResponse(ByVal RHS As
SSubTimer6.EMsgResponse)
'
End Property
' ****************
Private Property Get ISubclass_MsgResponse() As SSubTimer6.EMsgResponse
'
End Property
' ****************
Private Function ISubclass_WindowProc(ByVal hwnd As Long, ByVal iMsg As
Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case iMsg
Case WM_WTSSESSION_CHANGE
Select Case wParam
Case WTS_SESSION_LOCK
Chrono.Enabled = False
Case WTS_SESSION_UNLOCK
Chrono.Enabled = True
DEPART = Time - RESTE
Case Else
'
End Select
Case Else
'
End Select
End Function
' ****************
Private Sub Form_Load()
Dim ret As Boolean
Chrono.Interval = 250
Chrono.Enabled = True
DEPART = Time
ret = WTSRegisterSessionNotification(Me.hwnd, NOTIFY_FOR_THIS_SESSION)
If Not ret Then
Debug.Print GetError(Err.LastDllError)
Else
AttachMessage Me, Me.hwnd, WM_WTSSESSION_CHANGE
End If
End Sub
' ****************
Private Function GetError(ByVal lErrorNumber As Long) As String
Dim Buffer As String
Buffer = Space(200)
FormatMessage FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, lErrorNumber,
LANG_NEUTRAL, Buffer, 200, ByVal 0&
GetError = Buffer
End Function
' ****************
Sub Fin()
If Not WTSUnRegisterSessionNotification(Me.hwnd) Then
MsgBox (GetError(Err.LastDllError))
End If
DetachMessage Me, Me.hwnd, WM_WTSSESSION_CHANGE
End
End Sub
------------fin ( enfin ) du
code --------------------------------------------
Avatar
Clive Lumb
Bayosky wrote:

Seul défaut :
lors de la sortie ( sub Fin )
la détection d'erreur
provoque l'affichage du message "Opération réussie"
qui provient de MsgBox (GetError(Err.LastDllError))
Cela signifie que le test
If Not WTSUnRegisterSessionNotification(Me.hwnd)
n'est pas fiable :o)
donc pour la suite il faut "affiner" la detection d'erreur en
sortie...
en éliminant le N° d'erreur qui correspond à la réussite.




Est-ce que l'erreur arrive aussi en version compilée ?
Car le sub-classing et l'IDE...
Avatar
bayosky
Dans le message ,
Clive Lumb a écrit :

salut,

Est-ce que l'erreur arrive aussi en version compilée ?
Car le sub-classing et l'IDE...




je le saurais bientôt :o)

A+

HB
1 2