How to start autorun driver

I wrote a driver in Visual Studio 2013. The creation process was successful. Then I prepared the trag computer and copied the driver files to it. Then I installed the driver:

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 

It seems to have been successful. I launched DebugView on a PC, but now I do not know how to start the driver so that I can see the debug output. I have DbgPrintEx () - Statement in my source code.

Can someone tell me how to run this driver so that I can see the result.

This is the driver source code:

 #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; } 
+5
source share
3 answers

You need to make EXE (testapp), which will start your driver if the installation is already completed. You can use the code below in the application:

 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 )); 

You need to add the code according to your needs. Try it.

For more information, download driver samples and test applications provided by Microsoft.

+2
source

To start the driver, you can use the built-in command line tool "sc" (service control).

Syntax:

 sc start <name> 

So, if your driver is installed with the name "KmdfHelloWorld", the command should be:

 sc start KmdfHelloWorld 
0
source

I am currently writing a GPIO controller / driver for Windows 8.1 and Windows 10 and have had similar problems. The easiest way to run your driver is to configure and provide a computer to test drivers and use Visual Studio to deploy, install, and run your driver on a remote computer.

It is good practice to write your driver, then deploy and test remotely (either on another computer or on a virtual machine such as VirtualBox), as this reduces your chances of ruining the computer on which you are writing code.

To provide the computer, I used the following MSDN page: https://msdn.microsoft.com/en-us/library/windows/hardware/dn745909?f=255&MSPPError=-2147217396

By running pre-packaged tests, you can actually get a VS and Windows report on the status of the driver, get debugging information, and even set breakpoints. Believe me, for starters this is the easiest way to do this.

In addition, it would be unimportant to register and create a callback function for the default working state, so that your driver does something during operation. To do this, use EVT_WDF_DEVICE_D0_ENTRY define, as you did for EVT_WDF_DRIVER_DEVICE_ADD .

Happy coding!

0
source

All Articles