简体   繁体   English

如何捕获Windows Server 2003中取消的注销

[英]How to capture logoff cancelled in windows server 2003

I'm working on a terminal services based system running on windows 2003. It consists of a desktop replacement application from which the user starts programs. 我正在研究在Windows 2003上运行的基于终端服务的系统。它包含一个桌面替换应用程序,用户可以从中启动程序。 It also has a logoff-button. 它还有一个注销按钮。 When the user logs off two things must happen. 当用户注销时,必须发生两件事。 First off, he is logged out of windows. 首先,他退出了Windows。 Then a stored procedure is called cleaning up the users database state. 然后调用存储过程来清理用户数据库状态。 This almost works fine, but for one situation, and that is when the user cancels the logoff event. 这几乎可以正常工作,但对于一种情况,那就是用户取消注销事件。 Typical scenario: 1- User logs in, starts MS Word, edits the document, does not save. 典型场景:1-用户登录,启动MS Word,编辑文档,不保存。 2 - The user then presses the logoff button. 2 - 然后用户按下注销按钮。 3- MS Word reacts to this asking the user to save his changes. 3- MS Word对此做出反应,要求用户保存他的更改。 4 - The user presses cancel. 4 - 用户按下取消。

At this point the desktop application might already have called the stored procedure cleaning up the database state. 此时,桌面应用程序可能已经调用了存储过程来清理数据库状态。 How do I catch this behaviour in the desktop application? 如何在桌面应用程序中捕获此行为? Is there a message saying that the end session operation was cancelled? 是否有消息说结束会话操作被取消了?

Does my question make sense at all? 我的问题是否有意义?

Oh, all of the applications are written in Delphi 7, but I work in C, C++ and C# as well, so answers in those languages are appreciated as well. 哦,所有的应用程序都是用Delphi 7编写的,但我也在C,C ++和C#中工作,所以这些语言的答案也很受欢迎。

If your user state logic is inside your shell replacement then think of Application redesign: Decouple Custom Shell from Session management. 如果您的用户状态逻辑位于shell替换中,那么请考虑应用程序重新设计:从会话管理中解除自定义Shell。

For example: Move your User state logic in a service. 例如:在服务中移动用户状态逻辑。 Within this service register for RDS Notifications: WTS_SESSION_LOGON/WTS_SESSION_LOGOFF. 在此服务寄存器中,用于RDS通知:WTS_SESSION_LOGON / WTS_SESSION_LOGOFF。

I think WTS_SESSION_LOGOFF is sent only when actual logoff occurs ie if the user clicks Cancel button in Word then Windows would know that the user hasn't logged off actually and OS would not send WTS_SESSION_LOGOFF (this is untested, but sounds logical). 我认为WTS_SESSION_LOGOFF 在实际注销时发送,即如果用户单击Word中的“取消”按钮,则Windows将知道用户实际上没有注销,并且OS不会发送WTS_SESSION_LOGOFF(这是未经测试的,但听起来合乎逻辑)。

This way you don't deal with WM_ENDSESSION/WM_QUERYENDSESSION stuff. 这样你就不会处理WM_ENDSESSION / WM_QUERYENDSESSION的东西了。

Recently I wrote some guidance on RDS notifications topic. 最近我写了一些关于RDS通知主题的指南。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM