Namespace: Nefarius.Utilities.DeviceManagement.PnP
"Device Console" utility class. Managed wrapper for common SetupAPI actions.
public static class Devcon
Remarks:
https://docs.microsoft.com/en-us/windows-hardware/drivers/install/setupapi
Creates a virtual device node (hardware ID) in the provided device class.
public static bool Create(string className, Guid classGuid, string node)
className
String
The device class name.
classGuid
Guid
The GUID of the device class.
node
String
The node path terminated by two null characters.
True on success, false otherwise.
Uninstalls a driver identified via a given INF and optionally removes it from the driver store as well.
public static void DeleteDriver(string oemInfName, string fullInfPath, bool forceDelete)
oemInfName
String
The OEM INF name (name and extension only).
fullInfPath
String
The fully qualified absolute path to the INF to remove from driver store.
forceDelete
Boolean
Remove driver store copy, if true.
Do not use, see remarks.
Searches for devices matching the provided interface GUID and returns the device path and instance ID.
public static bool Find(Guid target, ref String path, ref String instanceId, int instance)
target
Guid
The class GUID to enumerate.
path
String&
The device path of the enumerated device.
instanceId
String&
The instance ID of the enumerated device.
instance
Int32
Optional instance ID (zero-based) specifying the device to process on multiple matches.
True if at least one device was found with the provided class, false otherwise.
Remarks:
This is here for backwards compatibility, please use Devcon.FindByInterfaceGuid(Guid, ref String, ref String, Int32, Boolean) instead.
Searches for devices matching the provided interface GUID and returns the device path and instance ID.
public static bool FindByInterfaceGuid(Guid target, ref String path, ref String instanceId, int instance, bool presentOnly)
target
Guid
The interface GUID to enumerate.
path
String&
The device path of the enumerated device.
instanceId
String&
The instance ID of the enumerated device.
instance
Int32
Optional instance ID (zero-based) specifying the device to process on multiple matches.
presentOnly
Boolean
Only enumerate currently connected devices by default, set to False to also include phantom
devices.
True if at least one device was found with the provided class, false otherwise.
Searches for devices matching the provided interface GUID and returns a PnPDevice.
public static bool FindByInterfaceGuid(Guid target, ref PnPDevice device, int instance, bool presentOnly)
target
Guid
The interface GUID to enumerate.
device
PnPDevice&
The PnPDevice wrapper object.
instance
Int32
Optional instance ID (zero-based) specifying the device to process on multiple matches.
presentOnly
Boolean
Only enumerate currently connected devices by default, set to False to also include phantom
devices.
True if at least one device was found with the provided class, false otherwise.
Attempts to find a device within a specified device class by a given hardware ID.
public static bool FindInDeviceClassByHardwareId(Guid target, string hardwareId)
target
Guid
The device class GUID.
hardwareId
String
The hardware ID to search for.
True if found, false otherwise.
Attempts to find a device within a specified device class by a given hardware ID.
public static bool FindInDeviceClassByHardwareId(Guid target, string hardwareId, ref IEnumerable`1 instanceIds)
target
Guid
The device class GUID.
hardwareId
String
The hardware ID to search for.
instanceIds
IEnumerable`1&
A list of instances found for the given search criteria.
True if found, false otherwise.
Attempts to find a device within a specified device class by a given hardware ID.
public static bool FindInDeviceClassByHardwareId(Guid target, string hardwareId, ref IEnumerable`1 instanceIds, bool presentOnly, bool allowPartial)
target
Guid
The device class GUID.
hardwareId
String
The hardware ID to search for.
instanceIds
IEnumerable`1&
A list of instances found for the given search criteria.
presentOnly
Boolean
True to filter currently plugged in devices, false to get all matching devices.
allowPartial
Boolean
True to match substrings, false to match the exact ID value.
True if found, false otherwise.
Invokes the installation of a driver via provided .INF file.
public static bool Install(string fullInfPath, ref Boolean rebootRequired)
fullInfPath
String
An absolute path to the .INF file to install.
rebootRequired
Boolean&
True if a machine reboot is required, false otherwise.
True on success, false otherwise.
Instructs the system to re-enumerate hardware devices.
public static bool Refresh()
True on success, false otherwise.
Instructs the system to re-enumerate hardware devices including disconnected ones.
public static bool RefreshPhantom()
True on success, false otherwise.
Removed a device node identified by class GUID, path and instance ID.
public static bool Remove(Guid classGuid, string instanceId)
classGuid
Guid
The device class GUID.
instanceId
String
The instance ID.
True on success, false otherwise.
Removed a device node identified by interface GUID and instance ID.
public static bool Remove(Guid classGuid, string instanceId, ref Boolean rebootRequired)
classGuid
Guid
The device class GUID.
instanceId
String
The instance ID.
rebootRequired
Boolean&
True if a reboot is required to complete the uninstall action, false otherwise.
True on success, false otherwise.
Given an INF file and a hardware ID, this function installs updated drivers for devices that match the hardware ID.
public static bool Update(string hardwareId, string fullInfPath, ref Boolean rebootRequired)
hardwareId
String
A string that supplies the hardware identifier to match existing devices on the computer.
fullInfPath
String
A string that supplies the full path file name of an INF file.
rebootRequired
Boolean&
A variable that indicates whether a restart is required and who should prompt for it.
The function returns TRUE if a device was upgraded to the specified driver. Otherwise, it returns FALSE and the logged error can be retrieved with a call to GetLastError.