Click here to Skip to main content
6,295,667 members and growing! (15,398 online)
Email Password   helpLost your password?
General Reading » Hardware & System » General     Intermediate

Taking Advantage of the Winlogon Notification Package

By Tony Truong

Taking advantage of the Winlogon Notification Package
VC6Win2K, Visual Studio, Dev
Posted:5 Jan 2001
Updated:6 Jan 2001
Views:164,429
Bookmarked:60 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
32 votes for this article.
Popularity: 6.84 Rating: 4.55 out of 5
1 vote, 5.9%
1

2
1 vote, 5.9%
3

4
15 votes, 88.2%
5

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

//sample.cpp


#include <windows.h>

#include <Winwlx.h>


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 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);	
        }
        break;
    }
    return TRUE;
}

//Event handler for the Winlogon Logon event

VOID 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 handlers

VOID 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

EXPORTS
StartProcessAtWinLogon
StopProcessAtWinLogoff

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Tony Truong


Member
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.
Occupation: Architect
Company: Frontline Direct Inc., Adconion
Location: United States United States

Other popular Hardware & System articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 98 (Total in Forum: 98) (Refresh)FirstPrevNext
GeneralCan I see the notpad's and logon's UI at same time? PinmemberAson22:14 18 Feb '09  
GeneralError:unresolved external symbol "int __cdecl SafeTerminateProcess(void *,unsigned int)" PinmemberRajeshshewale20:32 6 Jun '08  
GeneralWinLogon Notification Package PinmemberBodanapu1:45 14 Sep '07  
AnswerRe: WinLogon Notification Package PinmemberA5647188:22 28 Sep '07  
GeneralCan't make this thing to work Pinmembersdrey19:54 19 Jul '07  
GeneralNotification Packages removed on vista Pinmemberppckiller8:27 4 Jun '07  
Generalhow to create and use manifest file in winlogon package Pinmemberprem kumar singh2:47 22 Dec '06  
QuestionHow to bypass the logon windows( user to input username and password) PinmemberJohngle18:07 29 Oct '06  
QuestionComplete Sample for Novice PinmemberVindalf10:18 27 Aug '06  
GeneralWinlogon notification packages in Non-Domain env.! Pinmemberbaluspage21:30 17 Aug '06  
QuestionHow to get this code to work with VS.NET 2003? Pinmemberid10t3:44 24 May '06  
GeneralEvent DLL not working on clean install of XP ? Pinmembermojomonkeyhelper0:36 26 Sep '05  
GeneralRe: Event DLL not working on clean install of XP ? Pinmembermojomonkeyhelper0:00 27 Sep '05  
GeneralDebug version works, release version doesn't PinsussAaron Reeves12:29 3 May '05  
GeneralWorks on XP, does not work on 2003 Server PinmemberAlpar11:15 26 Apr '05  
GeneralNo more information than in MSDN, surely? PinmemberCoruscant13:41 6 Apr '05  
Generalchange winlogon notification package timeout? Pinmemberchca10:48 6 Jan '05  
GeneralRe: change winlogon notification package timeout? PinmemberBlake Miller13:07 25 Mar '05  
GeneralRe: change winlogon notification package timeout? Pinmemberchca3:32 26 Mar '05  
GeneralRe: change winlogon notification package timeout? PinmemberBlake Miller5:13 28 Mar '05  
GeneralLoading a Dialog at Winlogon Startup Notification is Super Slow Pinmemberdbmabin11:42 1 Nov '04  
GeneralRe: Loading a Dialog at Winlogon Startup Notification is Super Slow Pinmemberdbmabin12:04 9 Nov '04  
GeneralRe: Loading a Dialog at Winlogon Startup Notification is Super Slow PinmemberBlake Miller13:05 25 Mar '05  
General? Full documentation, Hibernate/Standby PinmemberSynetech8:05 16 Oct '04  
GeneralRe: ? Full documentation, Hibernate/Standby PinmemberBlake Miller13:02 25 Mar '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 6 Jan 2001
Editor: James Spibey
Copyright 2001 by Tony Truong
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project