WTSRegisterSessionNotification 有时在 XP home 启动时不起作用 [英] WTSRegisterSessionNotification doesn't work sometimes on startup with XP home

查看:20
本文介绍了WTSRegisterSessionNotification 有时在 XP home 启动时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用函数/消息来检查工作站是否被锁定.现在我的应用程序位于启动文件夹中.它在 XP pro 上运行没有任何问题,但是由于我在 XP home 上使用该程序,WTSRegisterSessionNotification 在启动时大约有 50% 的时间失败,但是当系统已经启动时它永远不会失败.知道为什么会发生这种情况吗?

I'm using the function/message to check if the workstation is locked. Now my application is in the startup folder. It has worked without any problems on XP pro, but since I'm using the program on XP home WTSRegisterSessionNotification fails about 50% of the time on startup, but it never fails when the system is already booted up. Any idea why this could happen?

推荐答案

在 XP 上,服务在后台启动并且不会阻止启动或登录.在您调用 WTSRegisterSessionNotification 时,termsrv 服务很可能没有运行.

On XP, services start in the background and do not block boot or logon. The termsrv service is most likely not running by the time you call WTSRegisterSessionNotification.

您可以通过以下方式检查服务是否正在运行:

You can check if the service is running by:

// Error handling omitted for brevity
SC_HANDLE scm = OpenSCManager(NULL, NULL, GENERIC_READ);
SC_HANDLE svc = OpenService(scm, L"TermSrv", SERVICE_QUERY_STATUS);
SERVICE_STATUS status;
QueryServiceStatus(svc, &status);
if (status.dwCurrentSTate != SERVICE_RUNNING) {
    // Try to start, wait and try again, etc.
}

CloseServiceHandle(svc);
CloseServiceHandle(scm);

这篇关于WTSRegisterSessionNotification 有时在 XP home 启动时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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