繁体   English   中英

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

[英]Good C++ driver install and controlling code

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

这是我几年前编写的用于安装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.
}

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM