/*++ Copyright (c) 1991 Microsoft Corporation Module Name: ts2.c Abstract: This is a test program for exercising the service controller. This program acts like a service and exercises the Service Controller API that can be called from a service: NetServiceStartCtrlDispatcher NetServiceRegisterCtrlHandler NetServiceStatus Contents: Grumpy Lumpy Dumpy Sleepy Dead SlowStop - Takes a long time to stop based on Message Box. Terminate - Starts normally, After 20 seconds, it sends a STOPPED status, and does an ExitProcess. Bad1 - Never calls RegisterServiceCtrlHandler. Bad2 - Stays in START_PENDING forever. Bad3 - Start= Sends 1 START_PENDING, then doesn't send any further status messages. Otherwise operates normally. Bad4 - Normal Start; On Stop it sends 1 stop pending status then terminates itself. HangOnStop - Doesn't return from CtrlHandl routine on Stop requests until 40 seconds has passed. (pipe timeout is 30 sec). Sends a RUNNING status after the 40 second wait, then it sleeps for 20 seconds before sending STOPPED status. StartAndDie - Takes 40 seconds to start, then it terminates right after saying it was started. Author: Dan Lafferty (danl) 12 Apr-1991 Environment: User Mode -Win32 Notes: optional-notes Revision History: --*/ // // Includes // #include // DbgPrint prototype #include // DbgPrint prototype #include #include // needed for winbase.h #include #include // for winuserp.h #include // MessageBox #include // STARTF_DESKTOPINHERIT #include // CONSOLE_SCREEN_BUFFER_INFO #include #include // Unicode string macros #include // printf // // Defines // #define INFINITE_WAIT_TIME 0xffffffff #define NULL_STRING TEXT(""); LPWSTR pszInteractiveDesktop=L"WinSta0\\Default"; // // Globals // HANDLE DbgLogFileHandle = INVALID_HANDLE_VALUE; SERVICE_STATUS GrumpyStatus; SERVICE_STATUS LumpyStatus; SERVICE_STATUS DumpyStatus; SERVICE_STATUS SleepyStatus; SERVICE_STATUS DeadStatus; SERVICE_STATUS SlowStopStatus; SERVICE_STATUS TerminateStatus; SERVICE_STATUS Bad1Status; SERVICE_STATUS Bad2Status; SERVICE_STATUS Bad3Status; SERVICE_STATUS Bad4Status; SERVICE_STATUS HangOnStopStatus; SERVICE_STATUS StartProcStatus; SERVICE_STATUS StartAndDieStatus; HANDLE GrumpyDoneEvent; HANDLE LumpyDoneEvent; HANDLE DumpyDoneEvent; HANDLE SleepyDoneEvent; HANDLE DeadDoneEvent; HANDLE SlowStopDoneEvent; HANDLE TerminateDoneEvent; HANDLE Bad1DoneEvent; HANDLE Bad2DoneEvent; HANDLE Bad3DoneEvent; HANDLE Bad4DoneEvent; HANDLE HangOnStopDoneEvent; HANDLE StartProcDoneEvent; HANDLE StartAndDieDoneEvent; SERVICE_STATUS_HANDLE GrumpyStatusHandle; SERVICE_STATUS_HANDLE LumpyStatusHandle; SERVICE_STATUS_HANDLE DumpyStatusHandle; SERVICE_STATUS_HANDLE SleepyStatusHandle; SERVICE_STATUS_HANDLE DeadStatusHandle; SERVICE_STATUS_HANDLE SlowStopStatusHandle; SERVICE_STATUS_HANDLE TerminateStatusHandle; SERVICE_STATUS_HANDLE Bad1StatusHandle; SERVICE_STATUS_HANDLE Bad2StatusHandle; SERVICE_STATUS_HANDLE Bad3StatusHandle; SERVICE_STATUS_HANDLE Bad4StatusHandle; SERVICE_STATUS_HANDLE HangOnStopStatusHandle; SERVICE_STATUS_HANDLE StartProcStatusHandle; SERVICE_STATUS_HANDLE StartAndDieStatusHandle; // // Function Prototypes // DWORD GrumpyStart ( DWORD argc, LPTSTR *argv ); DWORD LumpyStart ( DWORD argc, LPTSTR *argv ); DWORD DumpyStart ( DWORD argc, LPTSTR *argv ); DWORD SleepyStart ( DWORD argc, LPTSTR *argv ); DWORD DeadStart ( DWORD argc, LPTSTR *argv ); DWORD SlowStopStart ( DWORD argc, LPTSTR *argv ); DWORD TerminateStart ( DWORD argc, LPTSTR *argv ); DWORD Bad1Start (DWORD argc,LPTSTR *argv); DWORD Bad2Start (DWORD argc,LPTSTR *argv); DWORD Bad3Start (DWORD argc,LPTSTR *argv); DWORD Bad4Start (DWORD argc,LPTSTR *argv); DWORD HangOnStopStart (DWORD argc,LPTSTR *argv); DWORD StartProcStart (DWORD argc,LPTSTR *argv); DWORD StartAndDieStart (DWORD argc,LPTSTR *argv); VOID GrumpyCtrlHandler ( IN DWORD opcode ); VOID LumpyCtrlHandler ( IN DWORD opcode ); VOID DumpyCtrlHandler ( IN DWORD opcode ); VOID SleepyCtrlHandler ( IN DWORD opcode ); VOID DeadCtrlHandler ( IN DWORD opcode ); VOID SlowStopCtrlHandler ( IN DWORD opcode ); VOID TerminateCtrlHandler ( IN DWORD opcode ); VOID Bad1CtrlHandler (IN DWORD opcode); VOID Bad2CtrlHandler (IN DWORD opcode); VOID Bad3CtrlHandler (IN DWORD opcode); VOID Bad4CtrlHandler (IN DWORD opcode); VOID HangOnStopCtrlHandler (IN DWORD opcode); VOID StartProcCtrlHandler (IN DWORD opcode); VOID StartAndDieCtrlHandler (IN DWORD opcode); VOID SvcPrintf (char *Format, ...); VOID SetUpConsole(); /****************************************************************************/ VOID __cdecl main ( DWORD argc, PCHAR argv[] ) { DWORD i; SERVICE_TABLE_ENTRY DispatchTable[] = { { TEXT("StartProc"), StartProcStart }, { TEXT("grumpy"), GrumpyStart }, { TEXT("lumpy"), LumpyStart }, { TEXT("dumpy"), DumpyStart }, { TEXT("sleepy"), SleepyStart }, { TEXT("dead"), DeadStart }, { TEXT("slowstop"), SlowStopStart }, { TEXT("terminate"), TerminateStart }, { TEXT("Bad1"), Bad1Start }, { TEXT("Bad2"), Bad2Start }, { TEXT("Bad3"), Bad3Start }, { TEXT("Bad4"), Bad4Start }, { TEXT("HangOnStop"), HangOnStopStart }, { TEXT("StartAndDie"), StartAndDieStart }, { NULL, NULL } }; DbgPrint("[ts2]Args passed to .exe main() function:\n"); for (i=0; i