2016-05-30 203 views
5

我在Visual Studio 2013中编写了一个驱动程序。building-Process成功。 然后我准备了一个traget-computer并将驱动程序文件复制到它。 然后我安装了驱动程序:如何启动自写驱动程序

C:\Windows\system32>pnputil -a "E:\driverZeug\KmdfHelloWorldPackage\KmdfHelloWorld.inf" 
Microsoft-PnP-Dienstprogramm 

Verarbeitungsinf.:   KmdfHelloWorld.inf 
Das Treiberpaket wurde erfolgreich hinzugefügt. 
Veröffentlichter Name:   oem42.inf 


Versuche gesamt:    1 
Anzahl erfolgreicher Importe: 1 

现在看来似乎是成功的。 我在PC上运行DebugView,但现在我不知道如何启动驱动程序,以便我可以看到一个调试输出。我有一个DbgPrintEx() - 我的源代码中的声明。

有人可以告诉我如何启动这个驱动程序,以便我可以看到输出。

这是驱动程序的源代码:

#include <ntddk.h> 
#include <wdf.h> 
DRIVER_INITIALIZE DriverEntry; 
EVT_WDF_DRIVER_DEVICE_ADD KmdfHelloWorldEvtDeviceAdd; 

NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath) 
{ 
    NTSTATUS status; 
    WDF_DRIVER_CONFIG config; 

    DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: DriverEntry\n"); 
    KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: DriverEntry\n")); 
    WDF_DRIVER_CONFIG_INIT(&config, KmdfHelloWorldEvtDeviceAdd); 
    status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, WDF_NO_HANDLE); 
    return status; 
} 

NTSTATUS KmdfHelloWorldEvtDeviceAdd(_In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT DeviceInit) 
{ 
    NTSTATUS status; 
    WDFDEVICE hDevice; 
    UNREFERENCED_PARAMETER(Driver); 

    KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: KmdfHelloWorldEvtDeviceAdd\n")); 
    status = WdfDeviceCreate(&DeviceInit, WDF_NO_OBJECT_ATTRIBUTES, &hDevice); 
    return status; 
} 

回答

2

你需要做的EXE(testapp)如果安装已经完成启动驱动程序。您可以在应用程序中使用以下代码:

SC_HANDLE schService; 
SC_HANDLE schSCManager; 

schSCManager = OpenSCManager(NULL,     // local machine 
          NULL,     // local database 
          SC_MANAGER_ALL_ACCESS // access required 
          ); 

// Open the handle to the existing service. 
schService = OpenService(SchSCManager, 
         DriverName, //name of the driver 
         SERVICE_ALL_ACCESS 
         ); 

StartService(schService,  // service identifier 
        0,    // number of arguments 
        NULL   // pointer to arguments 
       )); 

您需要根据需要添加代码。尝试这个。

欲了解更多信息,请下载microsoft提供的示例驱动程序和测试应用程序。

0

您可以使用内置命令行“sc”(服务控制)工具来启动驱动程序。

的语法是:

sc start <name> 

所以,如果你的驱动程序安装一个名为“KmdfHelloWorld”的命令应该是:

sc start KmdfHelloWorld 
0

目前,我写了一个GPIO控制/驱动器Windows 8.1 & Windows 10并且有类似的问题。启动驱动程序的最简单方法是设置和配置计算机进行驱动程序测试,并使用Visual Studio在远程计算机上部署,安装和启动驱动程序。

编写驱动程序然后进行远程部署和测试(在另一台计算机或VirtualBox等虚拟机上)是一种很好的做法,因为这样可以减少您编写代码的计算机的混乱机率。

要提供一台电脑,我用下面的MSDN页: https://msdn.microsoft.com/en-us/library/windows/hardware/dn745909?f=255&MSPPError=-2147217396

通过运行预先打包的测试,实际上你可以对驾驶员的身份VS和Windows报告,获得调试信息,甚至设置断点。相信我,对于初学者来说,这是最简单的方法。

此外,注册并创建默认工作状态的回调函数并不会造成伤害,这样,您的驱动程序在运行时就会实际执行某些操作。为此,请使用EVT_WDF_DEVICE_D0_ENTRY定义,就像您为EVT_WDF_DRIVER_DEVICE_ADD所做的那样。

快乐编码!

相关问题