Click here to Skip to main content
12,556,931 members (52,564 online)
Click here to Skip to main content
Add your own
alternative version


78 bookmarked

Taking Advantage of the Winlogon Notification Package

, 6 Jan 2001 CPOL
Rate this:
Please Sign up or sign in to vote.
Taking advantage of the Winlogon Notification Package
<!-- Add the rest of your HTML here -->


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.


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


#include <windows.h>
#include <Winwlx.h>

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 Journal
SafeTerminateProcess(HANDLE hProcess, UINT uExitCode);   

//Entrance function for the DLL
BOOL WINAPI LibMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
    switch (dwReason)
        case DLL_PROCESS_ATTACH:
	    DisableThreadLibraryCalls (hInstance);	
    return TRUE;

//Event handler for the Winlogon Logon event
    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.
    //terminates the process
    SafeTerminateProcess(g_pi.hProcess, 0xDEADBEEF);  

//other event handlers


Step 2.) - the exports

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




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.

            \Windows NT
                                \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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Tony Truong
Architect Frontline Direct Inc., Adconion
United States United States
Tony Truong graduated from UCLA in Spring of 2001 and starting worked at Symantec Corporation as a Software Engineer. After a few years of developing various features for Norton SystemWorks, Tony moved to San Diego. He is currently writing database applications using ASP.NET and C# with the .NET Framework. Tony specializes in tara-byte databases with emphasis on high availability, optimization, and complex entity modeling.

You may also be interested in...


Comments and Discussions

QuestionWill not work on Vista and later. Pin
Assaf Levy4-Oct-11 5:17
memberAssaf Levy4-Oct-11 5:17 
AnswerRe: Will not work on Vista and later. Pin
isabelprgmr29-Aug-12 12:23
memberisabelprgmr29-Aug-12 12:23 
QuestionHow to start service... Pin
gothic_coder27-May-10 3:54
membergothic_coder27-May-10 3:54 
QuestionMinGW c/c++ attempt ...I'm stuck, any ideas? Pin
twohawks2-Mar-10 16:52
membertwohawks2-Mar-10 16:52 
AnswerRe: MinGW c/c++ attempt ...I'm stuck, any ideas? Pin
twohawks2-Mar-10 17:55
membertwohawks2-Mar-10 17:55 
AnswerRe: MinGW c/c++ attempt ...some progress... Pin
twohawks2-Mar-10 19:07
membertwohawks2-Mar-10 19:07 
QuestionCan I see the notpad's and logon's UI at same time? Pin
Ason18-Feb-09 21:14
memberAson18-Feb-09 21:14 
GeneralError:unresolved external symbol "int __cdecl SafeTerminateProcess(void *,unsigned int)" Pin
Rajeshshewale6-Jun-08 19:32
memberRajeshshewale6-Jun-08 19:32 
GeneralWinLogon Notification Package Pin
Bodanapu14-Sep-07 0:45
memberBodanapu14-Sep-07 0:45 
AnswerRe: WinLogon Notification Package Pin
A56471828-Sep-07 7:22
memberA56471828-Sep-07 7:22 
GeneralRe: WinLogon Notification Package Pin
Member 857955622-Feb-12 0:06
memberMember 857955622-Feb-12 0:06 
GeneralCan't make this thing to work Pin
sdrey19-Jul-07 18:54
membersdrey19-Jul-07 18:54 
GeneralNotification Packages removed on vista Pin
ppckiller4-Jun-07 7:27
memberppckiller4-Jun-07 7:27 
Questionhow to create and use manifest file in winlogon package Pin
prem kumar singh22-Dec-06 1:47
memberprem kumar singh22-Dec-06 1:47 
QuestionHow to bypass the logon windows( user to input username and password) Pin
Johngle29-Oct-06 17:07
memberJohngle29-Oct-06 17:07 
QuestionComplete Sample for Novice Pin
Vindalf27-Aug-06 9:18
memberVindalf27-Aug-06 9:18 
GeneralWinlogon notification packages in Non-Domain env.! Pin
baluspage17-Aug-06 20:30
memberbaluspage17-Aug-06 20:30 
QuestionHow to get this code to work with VS.NET 2003? Pin
id10t24-May-06 2:44
memberid10t24-May-06 2:44 
QuestionEvent DLL not working on clean install of XP ? Pin
mojomonkeyhelper25-Sep-05 23:36
membermojomonkeyhelper25-Sep-05 23:36 
AnswerRe: Event DLL not working on clean install of XP ? Pin
mojomonkeyhelper26-Sep-05 23:00
membermojomonkeyhelper26-Sep-05 23:00 
GeneralDebug version works, release version doesn't Pin
Aaron Reeves3-May-05 11:29
sussAaron Reeves3-May-05 11:29 
GeneralWorks on XP, does not work on 2003 Server Pin
Alpar26-Apr-05 10:15
memberAlpar26-Apr-05 10:15 
QuestionNo more information than in MSDN, surely? Pin
Coruscant6-Apr-05 12:41
memberCoruscant6-Apr-05 12:41 
Questionchange winlogon notification package timeout? Pin
chca6-Jan-05 9:48
memberchca6-Jan-05 9:48 
AnswerRe: change winlogon notification package timeout? Pin
Blake Miller25-Mar-05 12:07
memberBlake Miller25-Mar-05 12:07 
GeneralRe: change winlogon notification package timeout? Pin
chca26-Mar-05 2:32
memberchca26-Mar-05 2:32 
GeneralRe: change winlogon notification package timeout? Pin
Blake Miller28-Mar-05 4:13
memberBlake Miller28-Mar-05 4:13 
GeneralLoading a Dialog at Winlogon Startup Notification is Super Slow Pin
dbmabin1-Nov-04 10:42
memberdbmabin1-Nov-04 10:42 
GeneralRe: Loading a Dialog at Winlogon Startup Notification is Super Slow Pin
dbmabin9-Nov-04 11:04
memberdbmabin9-Nov-04 11:04 
GeneralRe: Loading a Dialog at Winlogon Startup Notification is Super Slow Pin
Blake Miller25-Mar-05 12:05
memberBlake Miller25-Mar-05 12:05 
General? Full documentation, Hibernate/Standby Pin
Synetech16-Oct-04 7:05
memberSynetech16-Oct-04 7:05 
GeneralRe: ? Full documentation, Hibernate/Standby Pin
Blake Miller25-Mar-05 12:02
memberBlake Miller25-Mar-05 12:02 
GeneralRe: ? Full documentation, Hibernate/Standby Pin
Coruscant6-Apr-05 12:38
memberCoruscant6-Apr-05 12:38 
GeneralRe: ? Full documentation, Hibernate/Standby Pin
Amit22038-Oct-07 3:19
memberAmit22038-Oct-07 3:19 
GeneralRe: ? Full documentation, Hibernate/Standby Pin
Michael Behan17-Apr-08 23:28
memberMichael Behan17-Apr-08 23:28 
Generalgina.dll implementing Pin
Tricksy23-May-04 16:11
memberTricksy23-May-04 16:11 
Aisha Ikram22-Apr-04 20:47
memberAisha Ikram22-Apr-04 20:47 
Mike Peck27-Sep-04 9:25
sussMike Peck27-Sep-04 9:25 
GeneralSomebody has some example Pin
Aitor Aiestaran21-Apr-04 1:06
memberAitor Aiestaran21-Apr-04 1:06 
GeneralRe: Somebody has some example Pin
Blake Miller25-Mar-05 11:58
memberBlake Miller25-Mar-05 11:58 
Generalhave shell wait for process to finish Pin
Magic Steven1-Apr-04 1:41
sussMagic Steven1-Apr-04 1:41 
Generalcreating event dll in mfc shared dll Pin
Xins10-Mar-04 17:04
memberXins10-Mar-04 17:04 
GeneralSame code in C# Pin
AgentM8-Mar-04 11:29
memberAgentM8-Mar-04 11:29 
GeneralRe: Same code in C# Pin
Tom Spink21-May-04 21:40
memberTom Spink21-May-04 21:40 
GeneralAutomatic logon Pin
Andrew Groothedde25-Feb-04 4:26
sussAndrew Groothedde25-Feb-04 4:26 
GeneralRe: Automatic logon Pin
SohailB3-Sep-05 20:56
memberSohailB3-Sep-05 20:56 
Questioncan I use it on PDC to get logon info of entire network Pin
vijayv3-Feb-04 20:06
membervijayv3-Feb-04 20:06 
GeneralWinlogon and AppBar Pin
jameyer7314-Jan-04 7:22
memberjameyer7314-Jan-04 7:22 
QuestionIs it true that the EXE loaded through this, will not give GUI??? Pin
Mr. Jigar Mehta6-Jan-04 2:16
memberMr. Jigar Mehta6-Jan-04 2:16 
AnswerRe: Is it true that the EXE loaded through this, will not give GUI??? Pin
Mr. Jigar Mehta20-Feb-04 0:36
memberMr. Jigar Mehta20-Feb-04 0:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161026.1 | Last Updated 7 Jan 2001
Article Copyright 2001 by Tony Truong
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid