Visual C++ 2008
如何确定当前交互式用户是否处于锁定桌面(Windows-Key L)或关闭屏幕(Vista或7),等待程序在注销期间关闭。
HDESK hd = OpenInputDesktop(0,false,READ_CONTROL);
对于默认桌面上的用户应用程序来说,这很好,但是在锁定或关机时,由于用户没有打开安全桌面对象的权限,错误代码5会失败。
从系统帐户下运行的服务调用它将返回错误1(无效函数)。我认为服务在任何情况下都是错误的会话(会话0),无法确定任何其他会话的交互式桌面。
我有一个在当前交互用户下运行的应用程序,同时系统服务也在运行,所以可以从这两个用户中执行代码。
我是否应该尝试枚举所有的会话、窗口站点和桌面?
即使这样,如果只能从会话0中的系统服务调用OpenInputDesktop,那么如何确定当前的交互式桌面呢?
发布于 2010-11-27 14:28:16
我想你可以试试这些方法:
来自当前交互式用户中运行的进程的
使用WTSRegisterSessionNotification
为会话更改通知注册。一旦注册,交互式进程将获得登录/注销通知。更多信息可以在这里找到:
http://msdn.microsoft.com/en-us/library/aa383841.aspx
http://blogs.msdn.com/b/oldnewthing/archive/2006/01/04/509194.aspx
来自服务的
- 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
调用。
发布于 2011-04-08 15:28:16
注意:关于WTSQuerySessionInformation
和WTSWinStationName
的MSDN
注意:尽管它的名称,指定此类型并不返回窗口站的名称。相反,它返回远程桌面服务会话的名称。每个远程桌面服务会话都与一个交互式窗口站相关联。目前,由于交互式窗口站唯一支持的窗口站名称是"WinSta0",因此每个会话都与自己的"WinSta0“窗口站相关联。有关更多信息,请参见窗口站点.
。
https://stackoverflow.com/questions/4260878
复制相似问题