⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jiurlcommon.cpp

📁 关于win2000核心编程的文章
💻 CPP
字号:
#include "JiurlCommon.h"

BOOL InstallDriver(IN SC_HANDLE  SchSCManager,
				   IN LPCTSTR    DriverName,
				   IN LPCTSTR    ServiceExe)
{
    SC_HANDLE  schService;
    DWORD      err;

    schService = CreateService (SchSCManager, DriverName, // name of service
		DriverName, // name to display
		SERVICE_ALL_ACCESS,
		SERVICE_KERNEL_DRIVER, // service type
		SERVICE_DEMAND_START,  // start type
		SERVICE_ERROR_NORMAL,  // error control type
		ServiceExe,            // service's binary
		NULL,                  // no load ordering group
		NULL,                  // no tag identifier
		NULL,                  // no dependencies
		NULL,                  // LocalSystem account
		NULL                   // no password
		);

    if (schService == NULL)
    {
        err = GetLastError();

        if (err == ERROR_SERVICE_EXISTS)
        {
			printf ("failure: CreateService, ERROR_SERVICE_EXISTS\n");
        }
        else
        {
            printf ("failure: CreateService (0x %x)\n",err);
        }

        return FALSE;
    }

    CloseServiceHandle (schService);

    return TRUE;
}


BOOL RemoveDriver(IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName)
{
    SC_HANDLE  schService;
    BOOL       ret;

    schService=OpenService(SchSCManager,DriverName,SERVICE_ALL_ACCESS);

    if (schService == NULL)
    {
        printf ("failure: OpenService (0x %x)\n", GetLastError());
        return FALSE;
    }

    ret = DeleteService (schService);

    if (ret==0)
    {
        printf ("failure: DeleteService (0x %x)\n",GetLastError());
    }

    CloseServiceHandle (schService);

    return ret;
}


BOOL StartDriver(IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName)
{
    SC_HANDLE  schService;
    BOOL       ret;
    DWORD      err;

    schService=OpenService(SchSCManager,DriverName,SERVICE_ALL_ACCESS);

    if (schService == NULL)
    {
        printf ("failure: OpenService (0x %x)\n", GetLastError());
        return FALSE;
    }

    ret = StartService (schService,    // service identifier
                        0,             // number of arguments
                        NULL           // pointer to arguments
                        );
    if (ret==0)
    {
        err = GetLastError();

		switch(err)
		{
		case ERROR_SERVICE_EXISTS:
			printf ("failure: StartService, ERROR_SERVICE_EXISTS\n");
			break;
		case 0x02://ERROR_FILE_NOT_FOUND:
			printf ("failure: StartService, The system cannot find the file specified.\n");
			break;
		default:
			printf ("failure: CreateService (0x %x)\n",err);
		}
    }

    CloseServiceHandle (schService);

    return ret;
}


BOOL StopDriver(IN SC_HANDLE SchSCManager, IN LPCTSTR DriverName)
{
    SC_HANDLE       schService;
    BOOL            ret;
    SERVICE_STATUS  serviceStatus;

    schService=OpenService(SchSCManager,DriverName,SERVICE_ALL_ACCESS);

    if (schService == NULL)
    {
        printf ("failure: OpenService (0x %x)\n", GetLastError());
        return FALSE;
    }

    ret = ControlService (schService,
                          SERVICE_CONTROL_STOP,
                          &serviceStatus
                          );
    if (ret==0)
    {
        printf ("failure: ControlService (0x%02x)\n",GetLastError());
    }

    CloseServiceHandle (schService);

    return ret;
}


void printfcolor(char *str, WORD color)
{
	HANDLE hOut;
	hOut=GetStdHandle(STD_OUTPUT_HANDLE);

	CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
	GetConsoleScreenBufferInfo(hOut, &csbiInfo);

	WORD wOldColorAttrs; 
	wOldColorAttrs = csbiInfo.wAttributes; 

	SetConsoleTextAttribute(hOut,color);
	printf("%s",str);
	SetConsoleTextAttribute(hOut, wOldColorAttrs);
}

void JiurlAbout()
{
	printfcolor("     ",0x70);
	printfcolor("J",0x70|0x04);
	printfcolor("IURL",0x70);
	printfcolor("                    ""                    ""  ",0x70);
	printfcolor(" ",0);
	printfcolor("http://jiurl.yeah.net",0x0f|0x8000);
	printfcolor(" ",0);
	printfcolor("     ",0x70);
	printf("\n");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -