Skip to content

Latest commit

 

History

History
225 lines (145 loc) · 12 KB

nf-newdev-diinstalldevice.md

File metadata and controls

225 lines (145 loc) · 12 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:newdev.DiInstallDevice
DiInstallDevice function (newdev.h)
The DiInstallDevice function installs a specified driver that is preinstalled in the driver store on a specified device that is present in the system.
DiInstallDevice
DiInstallDevice function [Device and Driver Installation]
devinst.diinstalldevice
di-rtns_a2abff84-96e6-43c3-85ab-fe095d11b689.xml
newdev/DiInstallDevice
devinst\diinstalldevice.htm
devinst
e107fc37-02cb-4d50-822c-1c6fd80d7532
12/05/2018
DiInstallDevice, DiInstallDevice function [Device and Driver Installation], devinst.diinstalldevice, di-rtns_a2abff84-96e6-43c3-85ab-fe095d11b689.xml, newdev/DiInstallDevice
newdev.h
Newdev.h
Desktop
Available in Windows Vista and later versions of Windows.
Newdev.lib
Newdev.dll
Windows
19H1
DiInstallDevice
newdev/DiInstallDevice
c++
APIRef
kbSyntax
DllExport
Newdev.dll
Ext-MS-Win-Newdev-Config-L1-1-1.dll
DiInstallDevice

DiInstallDevice function

-description

The DiInstallDevice function installs a specified driver that is preinstalled in the driver store on a specified device that is present in the system.

-parameters

-param hwndParent [in, optional]

A handle to the top-level window that DiInstallDevice uses to display any user interface component that is associated with installing the device. This parameter is optional and can be set to NULL.

-param DeviceInfoSet [in]

A handle to a device information set that contains a device information element that represents the specified device.

-param DeviceInfoData [in]

A pointer to an SP_DEVINFO_DATA structure that represents the specified device in the specified device information set.

-param DriverInfoData [in, optional]

An pointer to an SP_DRVINFO_DATA structure that specifies the driver to install on the specified device. This parameter is optional and can be set to NULL. If this parameter is NULL, DiInstallDevice searches the drivers preinstalled in the driver store for the driver that is the best match to the specified device, and, if one is found, installs the driver on the specified device.

-param Flags [in]

A value of type DWORD that specifies zero or the following flag:

DIIDFLAG_SHOWSEARCHUI

If the caller does not specify a driver (DriverInfoData is set to NULL) and DiInstallDevice does not locate a preinstalled driver that matches the specified device. Instead, DiInstallDevice displays the Found New Hardware wizard for the device.

DIIDFLAG_NOFINISHINSTALLUI

DiInstallDevice does not start finish-install wizard pages or finish-install actions. The caller of DiInstallDevice must start these operations. The caller should only specify this flag if the caller requires that finish-install wizard pages be invoked in the context of a caller-supplied user interface component.

DIIDFLAG_INSTALLNULLDRIVER

DiInstallDevice attempts to install a null driver on the specified device. If this flag is set, DiInstallDevice does not use the DriverInfoData parameter. DiInstallDevice removes all device settings and, if the device cannot run in raw mode, the function sets the status of the device to CM_PROB_FAILED_INSTALL. If DiInstallDevice cannot install a null driver, the resulting state of the device is the same as if the device was connected for the first time to the computer and Windows did not locate a driver for the device.

DIIDFLAG_INSTALLCOPYINFDRIVERS

Any additional INF file specified via a CopyINF directive will be installed on any device it is applicable to. Any failure in installing an additional INF will not cause the primary INF's installation to fail.

-param NeedReboot [out, optional]

A pointer to a value of type BOOL that DiInstallDevice sets to indicate whether a system restart is required to complete the installation. This parameter is optional and can be set to NULL. If this parameter is supplied and a system restart is required to complete the installation, DiInstallDevice sets the value to TRUE. In this case, the caller is responsible for restarting the system. If this parameter is supplied and a system restart is not required, DiInstallDevice sets this parameter to FALSE. If this parameter is NULL and a system restart is required to complete the installation, DiInstallDevice displays a system restart dialog box.

-returns

DiInstallDevice returns TRUE if the function successfully installed the specified driver on the specified device. Otherwise, DiInstallDevice returns FALSE and the logged error can be retrieved by making a call to GetLastError. Some of the more common error values that GetLastError might return are as follows:

Return code Description
ERROR_ACCESS_DENIED
The caller does not have Administrator privileges. By default, Windows Vista and Windows Server 2008 require that a calling process have Administrator privileges to install a driver on a device.
ERROR_INVALID_FLAGS
The value that is specified for Flags is not zero or a bitwise OR of the valid flags.
ERROR_IN_WOW64
The calling application is a 32-bit application that is attempting to execute in a 64-bit environment, which is not allowed. For more information, see Installing Devices on 64-Bit Systems.

-remarks

Only call DiInstallDevice if it is necessary to install a specific driver on a specific device. Otherwise, use UpdateDriverForPlugAndPlayDevices or DiInstallDriver to install a driver for a device. For more information about which of these functions to call to install a driver on a device, see SetupAPI Functions that Simplify Driver Installation.

Before calling DiInstallDevice, the caller must obtain an SP_DEVINFO_DATA structure to specify the device and, optionally, an SP_DRVINFO_DATA structure to specify a driver for the device.

To create a device information set that contains the specified device and to obtain an SP_DEVINFO_DATA structure for the device, do one of the following:

  • Call SetupDiGetClassDevs to retrieve a device information set that contains the device and then call SetupDiEnumDeviceInfo to enumerate the devices in the device information set. On each call, SetupDiEnumDeviceInfo returns an SP_DEVINFO_DATA structure that represents the enumerated device in the device information set. To obtain specific information about the enumerated device, call SetupDiGetDeviceProperty and supply the SP_DEVINFO_DATA structure that is returned by SetupDiEnumDeviceInfo.
    • OR -
  • Call SetupDiOpenDeviceInfo to add a device with a known device instance ID to the device information set. SetupDiOpenDeviceInfo returns an SP_DEVINFO_DATA structure that represents the device in the device information set.
To retrieve an SP_DRVINFO_DATA structure for a selected driver, call SetupDiBuildDriverInfoList to build a list of drivers for the device and then call SetupDiEnumDriverInfo to enumerate the elements of the driver list for the device. For each enumerated driver, SetupDiEnumDriverInfo retrieves an SP_DRVINFO_DATA structure that identifies the driver. SetupDiGetDriverInfoDetail can also be called to retrieve additional detail about an enumerated driver.

In general, an installation application should set NeedReboot to NULL. This ensures that DiInstallDevice prompts the user to restart the system if a restart is required to complete the installation. An application should supply a NeedReboot pointer only in the following cases:

  • The application must call DiInstallDevice several times to complete an installation. In this case, the application should record whether a TRUENeedReboot value is returned by any of the calls to DiInstallDevice and, if so, prompt the user to restart the system after the final call to DiInstallDevice returns.
  • The application must perform required operations, other than calling DiInstallDevice, before a system restart should occur. If a system restart is required, the application should finish the required operations and then prompt the user to restart the system.
  • The application is a class installer, in which case, the class installer should set the DI_NEEDREBOOT flag in the Flags member of the SP_DEVINSTALL_PARAMS structure for a device.

-see-also

DiInstallDriver

SetupDiBuildDriverInfoList

SetupDiEnumDeviceInfo

SetupDiEnumDriverInfo

SetupDiGetClassDevs

SetupDiGetDeviceProperty

SetupDiGetDriverInfoDetail

SetupDiOpenDeviceInfo

UpdateDriverForPlugAndPlayDevices