All pastes #905989 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-02-16 05:22 UTC
rendered paste body
void cInstallService()
{
	SC_HANDLE SCManager;
	SC_HANDLE SCService;
	TCHAR szPath[MAX_PATH];

    if( !GetModuleFileName( NULL, szPath, MAX_PATH ) )
    {
        printf("Cannot Install Service", GetLastError());
        return;
    }

	SCManager = OpenSCManager(NULL, NULL,  SC_MANAGER_CREATE_SERVICE);
	printf("Load Driver\n");
	if(SCManager == 0)
	{
		printf("SCManager handle failed", GetLastError());
		return;
	}
	printf("CreateService\n");
	SCService = CreateService(SCManager,
							  "hello",
							  "Hello Driver",
							  SERVICE_START | DELETE | SERVICE_STOP, 
                                  SERVICE_KERNEL_DRIVER,
                                  SERVICE_DEMAND_START, 
                                  SERVICE_ERROR_IGNORE, 
							  "C:\\hello.sys",
							  NULL,
							  NULL,
							  NULL,
							  NULL,
							  NULL);

	if(SCService == NULL)
	{
		printf("CreateService failed", GetLastError());
		CloseServiceHandle(SCManager);
		return;
	}
    else printf("Service installed successfully\n"); 


    CloseServiceHandle(SCService); 
    CloseServiceHandle(SCManager);
}