好的C ++驱动程序安装和控制代码

时间:2012-10-08 16:48:30

标签: c++ kernel driver

我有一个内核驱动程序(.sys),在那里我可以找到可以用来安装和控制这个驱动程序的好资源?

2 个答案:

答案 0 :(得分:1)

这是我几年前写的一些安装NDIS驱动程序的代码。它已经过测试并在XP上使用,但我不确定是什么比这更新。安装不同类型的驱动程序主要需要更改组和依赖关系。

#define Win32_LEAN_AND_MEAN
#include <windows.h>

void install_NDIS_driver(char const *path, char const *name ) {
// This uses the name as both the driver name and the display name.

    SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
    SC_HANDLE service = CreateService(manager, 
        name,                       // driver name
        name,                       // driver display name
        GENERIC_EXECUTE,            // allow ourselves to start the service.
        SERVICE_KERNEL_DRIVER,      // type of driver.
        SERVICE_SYSTEM_START,       // starts after boot drivers.
        SERVICE_ERROR_NORMAL,       // log any problems, but don't crash if it can't be loaded.
        path,                       // path to binary file.
        "NDIS",                     // group to which this driver belongs.
        NULL,                       
        "NDIS\0",                   // driver we depend upon.
        NULL,                       // run from the default LocalSystem account.
        NULL);                      // don't need a password for LocalSystem .
    // The driver is now installed in the machine.  We'll try to start it dynamically.

    StartService(service, 0, NULL); // no arguments - drivers get their "stuff" from the registry.

    CloseServiceHandle(service);    // We're done with the service handle
    CloseServiceHandle(manager);    // and with the service manager.
}

答案 1 :(得分:0)

您可以使用Windows Service Controller注册和控制内核模式驱动程序。

  1. 使用带有type = kernel的“sc create”和指向.sys文件的binPath来创建服务
  2. 使用“sc start”和“sc stop”来控制驱动程序