简体   繁体   English

如何监视Windows Server 2003/2008用户登录?

[英]How to monitor windows server 2003/2008 user logins?

I wanna write a program that should perform some tasks automatically if someone logs onto my server. 我想编写一个程序,如果有人登录到我的服务器,该程序应自动执行一些任务。

My questions regarding this are: 我对此的疑问是:

  • 1) Is there a last login record that is set right after a user logs in that I can use/monitor for my purpose? 1)是否存在在用户登录后立即设置的最后一个登录记录,以供我使用/监视? If not is there something similar I can use? 如果没有,我可以使用类似的东西吗?

  • 2) What's the best way to constantly monitor such a value? 2)持续监控此值的最佳方法是什么?

Your best (and by far safest) bet is to create a service that accepts the SERVICE_CONTROL_SESSIONCHANGE control. 最好(也是迄今为止最安全)的选择是创建一个接受SERVICE_CONTROL_SESSIONCHANGE控件的服务。

This will allow your service control handler to receive a control whenever a user logs on, logs off, locks the session, and various other options. 这将使您的服务控件处理程序可以在用户登录,注销,锁定会话以及其他各种选项时接收控件。 Look for more info in a link blow. 在链接打击中查找更多信息。

This is done by creating a service which has the SERVICE_ACCEPT_SESSIONCHANGE flag in the dwControlsAccepted, as following: 这是通过创建一个在dwControlsAccepted中具有SERVICE_ACCEPT_SESSIONCHANGE标志的服务来完成的,如下所示:

SERVICE_STATUS ss;
...
ss.dwControlsAccepted |= SERVICE_ACCEPT_SESSIONCHANGE;

Followed by: 其次是:

// This lets the service accept the session change ctrls
// The service handle here is received by calling RegisterServiceCtrlHandler
SetServiceStatus(hServiceHandle,
                 &ss);

This will allow windows to send SERVICE_CONTROL_SESSIONCHANGE controls to your HandlerEx function, which should look something like this: 这将允许Windows将SERVICE_CONTROL_SESSIONCHANGE控件发送到HandlerEx函数,该控件应如下所示:

DWORD WINAPI HandlerEx(DWORD dwControl,
                       DWORD dwEventType, 
                       LPVOID lpEventData, 
                       LPVOID lpContext)
{
   switch (dwControl)
   {
    ...// Regular control handling
       case (SERVICE_CONTROL_SESSIONCHANGE):
            switch(dwEventType)
            {
                case(WTS_SESSION_LOGON):
                    // Handle logon
                break;

                case(WTS_SESSION_LOCK):
                    // Handle lock
                break;
                ...
            }
       break;

       ...
   }
}

You can read up on all the different session change notifications you can receive from here: WM_WTSSESSION_CHANGE , all the notifications you'll need are in the wParam part of the description. 您可以从以下网址阅读所有不同的会话更改通知: WM_WTSSESSION_CHANGE ,所有需要的通知都在说明的wParam部分中。

Well, that's the gist of it anyway. 好吧,无论如何这就是要点。 You can read more info on the handlerex function here: HandlerEx and more information about services in general here: Service Functions . 您可以在此处阅读更多关于handlerex函数的信息: HandlerEx,并在此处阅读有关服务的更多信息: 服务函数 I suggest you read up on the ServiceMain function, RegisterServiceCtrlHandler function and, most importantly, read the examples posted on the MSDN pages. 我建议您阅读ServiceMain函数,RegisterServiceCtrlHandler函数,并且最重要的是,阅读MSDN页面上发布的示例。 They're super helpful. 他们超级有帮助。

Good luck! 祝好运!

Why not just deploy a login script? 为什么不只是部署登录脚本? Will save you some hassle. 将为您节省一些麻烦。

暂无
暂无

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

相关问题 如何使用WMI或其他CMI中的WMI检测安装在Windows 2003服务器和2008 Server 2003服务器R2和2008服务器R2上的防病毒软件 - How to detect antivirus installed on windows 2003 server and 2008 server 2003 server R2and 2008 server R2 using WMI or other then WMI in C++ Windows Server 2003上的GetTokenInformation失败(错误998),但在2008年有效 - GetTokenInformation fails (error 998) on windows server 2003 but works on 2008 如何捕获Windows Server 2003中取消的注销 - How to capture logoff cancelled in windows server 2003 Windows Service启动过程终止通知(2003,2008) - Windows Service end of starting process notification (2003,2008) Windows Server 2003中条件变量的选项 - options for condition variable in windows server 2003 在 Windows Server 2003 中注册 dll 的问题 - Problems registering a dll in Windows Server 2003 如何在Windows Server 2003及更高版本上使用虚拟磁盘服务(VDS)登录到iSCSI目标? - How do I log into an iSCSI target using Virtual Disk Service (VDS) on Windows Server 2003 and higher? Visual Studio 2013中支持Windows XP和Windows Server 2003 - Windows XP and Windows Server 2003 support in Visual Studio 2013 如何检查Windows Server 2008上的进程是否仍在运行? - How to check if process is still running on Windows server 2008? 如何使64位dll与Windows Server 2008,Windows 7和Windows XP的64位版本兼容? - How to make 64 bit dll compatible with 64-bit editions of Windows Server 2008, Windows 7, and Windows XP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM