2012-10-08 67 views
0

我有一個內核驅動程序(.sys),我可以找到很好的來源,我可以用它來安裝和控制這個驅動程序?良好的C++驅動程序安裝和控制代碼

+0

你在說什麼系統?在任何情況下,這個網站都是關於編寫源代碼,而不是找到現有的代碼。 –

+0

@JerryCoffin Windows,驅動程序XP,Vista,7,8 – Roman

回答

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. 
} 
+0

我已經改變了一些代碼,一切ok,謝謝 – Roman

0

您可以使用Windows Service Controller來註冊和控制內核模式驅動程序。

  1. 使用「SC創建」類型=內核和binPath指向您的.sys文件來創建服務
  2. 使用「SC開始」和「停止SC」,以控制驅動器