博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Taking Advantage of the Winlogon Notification Package
阅读量:6387 次
发布时间:2019-06-23

本文共 3760 字,大约阅读时间需要 12 分钟。

Introduction

The Winlogon Notification Package is a DLL which exports functions that handle Winlogon.exe events. These event messages includes lock, unlock, logoff, logon, startup, shutdown, startscreensaver, stopscreensaver, and startshell. 

This article demonstrates how to use the Winlogon Notification Package as an alternative to NT Services. The main benefits for doing this is better handling of user activities. In addition, the Winlogon Notification Package will be very lightweight and requires much less code then its NT service equivalent. 

The Steps

Creating a Winlogon Notification package is very simple. Just create a DLL with specific functions to run during the Winlogon event messages. To let Winlogon.exe know about your DLL, simply add a few entries into the registry where appropriate. This method can be quite robust and versatile when combined with your services and applications.

Sample

This sample starts a WIN32 application before the user logon. Because the process is started by Winlogon, it is owned by the system account. Users may not end the process through 'End Task'. This is the exact way NT services behave. In this sample, the logoff notification will terminate the process. If the process needed to stay active, the EndProcessAtWinlogoff function should be removed. If we wanted the process to be owned by the user, we could use CreateProcessAsUser during a startup notification instead of a logon notification. 

Step 1.) - the dll

Collapse
//sample.cpp#include 
#include
PROCESS_INFORMATION g_pi;TCHAR g_szPath[] = _T("c:\somepath\execut.exe \"arguments\"");//This function safely terminates a process, allowing//it to do cleanup (ie. DLL detach)//It can be found at the Windows Developer's JournalSafeTerminateProcess(HANDLE hProcess, UINT uExitCode);//Entrance function for the DLLBOOL WINAPI LibMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved){switch (dwReason){case DLL_PROCESS_ATTACH:{DisableThreadLibraryCalls (hInstance);}break;}return TRUE;}//Event handler for the Winlogon Logon eventVOID APIENTRY StartProcessAtWinLogon (PWLX_NOTIFICATION_INFO pInfo){STARTUPINFO si;si.cb = sizeof(STARTUPINFO);si.lpReserved = NULL;si.lpTitle = NULL;si.lpDesktop = "WinSta0\\Default";si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L;si.dwFlags = 0;;si.wShowWindow = SW_SHOW;si.lpReserved2 = NULL;si.cbReserved2 = 0;CreateProcess(NULL, g_szPath, NULL, NULL, FALSE, CREATE_NEW_CONSOLE,NULL, NULL, &si, &g_pi);}//Event handler for the Winlogon Logoff event.VOID APIENTRY StopProcessAtWinLogoff (PWLX_NOTIFICATION_INFO pInfo){//terminates the process SafeTerminateProcess(g_pi.hProcess, 0xDEADBEEF);}//other event handlersVOID APIENTRY YOUR_EVENT_HANDLERS (PWLX_NOTIFICATION_INFO pInfo){//code}...

Step 2.) - the exports

The program hasn't exported any functions yet. We need to create a .def file.

sample.def

EXPORTSStartProcessAtWinLogonStopProcessAtWinLogoff

 

Now add the following to your linkage options in VC6 and build.

/def: "sample.def"

If everything went well, the files sample.dll and sample.exp will be in your output folder. Move these to \%NTROOT%\system32

Step 3.) - the registry

Add the following values and keys to the registry. These values communicate to Winlogon.exe and let it know which procedures to run during an event notification. Add as few or as many notification events as needed.

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Notify\NameOfProject\Asynchronous  REG_DWORD  0\Dllname       REG_SZ     NameOfDll.dll\Impersonate   REG_DWORD  0\Logon         REG_SZ     StartProcessAtWinLogon\Logoff        REG_SZ     StopProcessAtWinLogoff\...           REG_SZ     NameOfFunction

That's it! Now restart and Winlogon.exe will launch your app.

转载地址:http://ksdha.baihongyu.com/

你可能感兴趣的文章
腾讯云国内节点centos7.2安装k8sv1.12.3
查看>>
Python爬虫--- 1.5 爬虫实践: 获取百度贴吧内容
查看>>
解决Shell脚本$'\r': command not found问题
查看>>
ionic3使用百度地图
查看>>
JavaWEB开发11——JSP
查看>>
轻松搞定javascript中this的指向
查看>>
每天一个设计模式之单例模式
查看>>
Image Load Error Handler
查看>>
易燃易爆炸---python对Excel操作的面试题
查看>>
Vue2.5笔记:Vue中的模版
查看>>
策略路由基础命令(Linux)分享
查看>>
linux下磁盘挂载与查看
查看>>
javascript 闭包
查看>>
如何减少浏览器repaint和reflow(上)
查看>>
Exchange 2010之收件人对象管理
查看>>
Yarn详解
查看>>
C与C++《精通Unix下C语言与项目实践》读书笔记(8)
查看>>
初始化linux系统脚本
查看>>
计算机达人成长之路(6)连载
查看>>
raid5分析结果(临时)
查看>>