OpenInputDesktop()确定安全/登录桌面 [英] OpenInputDesktop() to determine Secure/Login desktop

查看:698
本文介绍了OpenInputDesktop()确定安全/登录桌面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual C ++ 2008

Visual C++ 2008

如何确定当前交互式用户是否位于锁定桌面(Windows键L)或关机屏幕(Vista或7)等待程序在注销期间关闭。

How to establish whether or not the currently interactive user is at either the Locked desktop (Windows-Key L) or the Shutdown Screen (Vista or 7) waiting for programs to close during log-out.

HDESK hd = OpenInputDesktop(0,false,READ_CONTROL);

HDESK hd = OpenInputDesktop(0, false, READ_CONTROL);

这对于默认桌面上的用户应用程序正常工作,但是在锁定或关闭桌面上,由于用户没有权限打开安全桌面对象的权限,因此失败并显示错误代码5。

This works fine for a user app on the Default desktop, but fails with error Code 5 when at the Locked or Shutdown desktops due to, I understand, the user not having permissions to open the secure desktop object.

从在SYSTEM帐户下运行的服务调用此命令将返回错误1(无效的函数)。我认为该服务无论如何都在错误的会话(会话0)中,并且无法确定任何其他会话的交互式桌面。

Calling this from a Service running under the SYSTEM account returns error 1 (invalid function). I believe that the Service is in any case in the wrong session (Session 0) and is unable to determine the interactive desktop for any other session.

我正在运行一个应用程序

I have an app running under the currently interactive user, and also, the system service running, so could do the code from either.

我可能应该尝试枚举所有会话,以及Window站。和台式机?

Should I perhaps attempt to enumerate all of the sessions, Window stations and desktops?

即使我只能在会话0中从SYSTEM服务调用OpenInputDesktop,如何确定当前交互的台式机呢?

Even then how do I determine the currently interactive desktop if I can only make the call to OpenInputDesktop from the SYSTEM service in session 0?

推荐答案

我认为您可以尝试以下方法:

I think you can try these methods:



  • 从当前正在交互用户中运行的进程中:

    使用 WTSRegisterSessionNotification 注册会话更改通知。一旦注册,交互过程将获得登录/注销通知。可在此处找到更多信息:

    http://msdn.microsoft.com/zh-cn/library/aa383841.aspx

    http://blogs.msdn。 com / b / oldnewthing / archive / 2006/01/04 / 509194.aspx




  • 来自服务(在会话0):


    • 使用 GetProcessWindowStation 获取当前站的服务句柄,并将其保存为

    • 使用 WTSGetActiveConsoleSessionId 获取当前交互式会话的会话ID。

    • 获取

    • WTSQuerySessionInformation WTSWinStationName 信息类的当前会话ID对应的工作站名称。

    • 使用 OpenWindowStation 打开此站。使用 SetProcessWindowStation 将此工作站设置为您的服务进程。

    • 现在,您可以使用 OpenInputDesktop 检查用户是否已登录。

    • 通过调用 CloseWindowStation 关闭打开的交互式Window站。通过调用 SetProcessWindowStation 并保存较早的站句柄来重置服务的原始窗口站。


    • From a process running in currently interactive user:
      Use WTSRegisterSessionNotification to register for session change notifications. Once registered, interactive process would get logon/logoff notifications. More info can be found here:
      http://msdn.microsoft.com/en-us/library/aa383841.aspx
      http://blogs.msdn.com/b/oldnewthing/archive/2006/01/04/509194.aspx

    • From a service (running in session 0):
      • Use GetProcessWindowStation to get the current station handle of service, and save it for later use.
      • Use WTSGetActiveConsoleSessionId to get session id of current interactive session.
      • Get station name corresponding to current session id using WTSQuerySessionInformation with WTSWinStationName info class.
      • Open this station using OpenWindowStation. Set this station to your service process using SetProcessWindowStation.
      • Now, you can use OpenInputDesktop to check if user has logged-in or not.
      • Close the opened interactive window station by calling CloseWindowStation. Reset the original window station of service by calling SetProcessWindowStation with station handle saved earlier.

      PS:当前, WinSta0 是Windows中唯一的交互式工作站。因此,您可以跳过 WTSGetActiveConsoleSessionId WTSQuerySessionInformation 调用。

      PS: Currently, "WinSta0" is the only interactive station in Windows. So, you can skip WTSGetActiveConsoleSessionId and WTSQuerySessionInformation calls.

      这篇关于OpenInputDesktop()确定安全/登录桌面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆