Export (0) Print
Expand All
Expand Minimize

DiInstallDevice function

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

Syntax


BOOL DiInstallDevice(
  _In_opt_   HWND hwndParent,
  _In_       HDEVINFO DeviceInfoSet,
  _In_       PSP_DEVINFO_DATA DeviceInfoData,
  _In_opt_   PSP_DRVINFO_DATA DriverInfoData,
  _In_       DWORD Flags,
  _Out_opt_  PBOOL NeedReboot
);

Parameters

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.

DeviceInfoSet [in]

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

DeviceInfoData [in]

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

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.

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.

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.

Return value

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 codeDescription
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.

Requirements

Version

Available in Windows Vista and later versions of Windows.

Header

Newdev.h (include Newdev.h)

Library

Newdev.lib

See also

DiInstallDriver
SetupDiBuildDriverInfoList
SetupDiEnumDeviceInfo
SetupDiEnumDriverInfo
SetupDiGetClassDevs
SetupDiGetDeviceProperty
SetupDiGetDriverInfoDetail
SetupDiOpenDeviceInfo
UpdateDriverForPlugAndPlayDevices

 

 

Send comments about this topic to Microsoft

Show:
© 2014 Microsoft