////////////////////////////////////////////////////////
//  pcidebug.dll
//                        Aug 20 1999 kashiwano masahiro
//
////////////////////////////////////////////////////////
#include "stdafx.h"
#include <windows.h>
/*
	TRUE	
	FALSE	
			
	filename	
	drivername	
				UnloadDriver

*/
BOOL LoadDriver(char *filename, char *drivername)
{
    SC_HANDLE	hSCManager;
    SC_HANDLE	hService;
    SERVICE_STATUS	serviceStatus;
    BOOL	ret;

	// 
	hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if(!hSCManager)
		return FALSE;

	//
	hService = OpenServiceA( hSCManager,
							drivername,
							SERVICE_ALL_ACCESS);
	if(hService){
		// 
		// 
		// 
		ret = ControlService(hService, SERVICE_CONTROL_STOP, &serviceStatus);
		ret = DeleteService(hService);
		CloseServiceHandle(hService);
	}
	//
	hService = CreateServiceA(hSCManager,
		drivername,
		drivername,
		SERVICE_ALL_ACCESS,
		SERVICE_KERNEL_DRIVER, // 
		SERVICE_DEMAND_START,  // 
		SERVICE_ERROR_NORMAL,
		filename,            // 
		NULL,NULL,NULL,NULL,NULL);

	ret = FALSE;
    if(hService) {

		// 
		ret = StartService(hService, 0, NULL);

		// 
		CloseServiceHandle(hService);
	}
	// 
	CloseServiceHandle(hSCManager);

	return ret;
}

/*
	TRUE	
	FALSE	


	drivername	
*/
BOOL UnloadDriver(char *drivername)
{
	SC_HANDLE	hSCManager;
	SC_HANDLE	hService;
	SERVICE_STATUS  serviceStatus;
	BOOL	ret;

	// 
    hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if(!hSCManager)
		return FALSE;

    // 
    hService = OpenServiceA(hSCManager, drivername, SERVICE_ALL_ACCESS);
	ret = FALSE;
	if(hService) {
	    // 
	    ret = ControlService(hService, SERVICE_CONTROL_STOP, &serviceStatus);

	    // 
	    if(ret == TRUE)
	        ret = DeleteService(hService);

	    // 
	    CloseServiceHandle(hService);
	}
	// 
    CloseServiceHandle(hSCManager);

    return ret;
}
