0

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

4

2 回答 2

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.
}
于 2012-10-08T17:05:16.037 回答
0

您可以使用Windows 服务控制器来注册和控制内核模式驱动程序。

  1. 使用带有 type=kernel 和 binPath 的“sc create”指向您的 .sys 文件来创建服务
  2. 使用“sc start”和“sc stop”来控制驱动
于 2012-10-08T16:58:47.090 回答