Usually when we complete a driver compilation, we use the inf file to install the driver. But sometimes we hope to install drivers dynamically
or install a driver as a service for Windows. In this article, we assume that the driver has been compiled and used directly. The driver must have 32-bit
and 64-bit versions so that we can experiment under 32-bit and 64-bit Operating Systems. How to compile a driver is not the task of this article.
About the path of the driver file which will be installed: usually we may place the installation program and driver file in the same directory.
In most cases, it is feasible. But if you want to install the driver as a service for Windows on a 64-bit Operating System environment, it will fail.
In this case the directory of the driver file must be "C:\\Windows\\System32\\drivers" so we use "C:\\Windows\\System32\\drivers"
instead of the current directory. The driver file is copied to the directory in advance.
Using the code
- Install a driver invoke function
GJ_Install_ADL_Driver_BOOT_START(). Uninstall a driver invoke function
- Setting the directory of the driver file refers to the function
SetupDriverName. The code for how to set the current path is available in the full source code.
__inout_bcount_full(BufferLength) PCHAR DriverLocation,
__in ULONG BufferLength
DWORD driverLocLen = 0;
if (FAILED( StringCbCatA(DriverLocation, BufferLength,
- The key to installing drivers dynamically or installing a driver as a service is the API function
schService = CreateService(SchSCManager,
You can change the sixth parameter "
dwStartType" to set the startup type.
The service start options can be one of the following values:
|A service started automatically by the service control manager during system startup. For more information,
see Automatically Starting Services.|
|A device driver started by the system loader. This value is valid only for driver services.|
|A service started by the service control manager when a process calls
function. For more information, see Starting Services on Demand.
|A service that cannot be started. Attempts to start the service results in the error code |
|A device driver started by the |
IoInitSystem function. This value is valid only for driver services.