Exemplo n.º 1
0
//-----------------------------------------------------------------------------
// main()
//-----------------------------------------------------------------------------
// 
//-----------------------------------------------------------------------------
int main(int argc, _TCHAR* argv[])
{
	int rc=0;
	
	TRACE_OPEN();
	TRACE((TRACE_ENTER,_F_,""));
	SERVICE_TABLE_ENTRY st[] =
    {
        { "swSSORecoverSvc", (LPSERVICE_MAIN_FUNCTION)ServiceMain },
        { NULL, NULL }
    };
	gdwThreadID = GetCurrentThreadId();
	ghServiceStatus = NULL;
    gServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
    gServiceStatus.dwCurrentState = SERVICE_STOPPED;
    gServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
    gServiceStatus.dwWin32ExitCode = 0;
    gServiceStatus.dwServiceSpecificExitCode = 0;
    gServiceStatus.dwCheckPoint = 0;
    gServiceStatus.dwWaitHint = 0;
	if (argc==2)
	{
		if (strcmp(argv[1],"install")==0)
		{
			if (IsInstalled()) { printf ("Already installed\n"); goto end; }
			rc=Install();
			if (rc==0)
				printf("Service installed successfully\n"); 
			else
				printf("Service installation failed\n");
		}
		else if (strcmp(argv[1],"uninstall")==0)
		{
			if (!IsInstalled()) { printf ("Not installed\n"); goto end; }
			rc=Uninstall();
			if (rc==0)
				printf("Service uninstalled successfully\n"); 
			else
				printf("Service installation failed\n");
		}
		else
			{ Usage(); rc=-1; goto end; }
	}
	else if (argc==1)
	{ 
		StartServiceCtrlDispatcher(st);
	}
	else 
		{ Usage(); rc=-1; goto end; }
end:
	TRACE((TRACE_LEAVE,_F_,""));
	TRACE_CLOSE();
	return rc;
}
Exemplo n.º 2
0
// DllMain: Entry-point for the DLL.
BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        g_hModule = (HMODULE)hModule;
        TRACE_INIT();
        break;

    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
        break;

    case DLL_PROCESS_DETACH:
        TRACE_CLOSE();
        break;
    }
    return TRUE;
}