Skip to content

Latest commit

 

History

History
336 lines (205 loc) · 10.8 KB

nefarius.utilities.devicemanagement.pnp.devcon.md

File metadata and controls

336 lines (205 loc) · 10.8 KB

Devcon

Namespace: Nefarius.Utilities.DeviceManagement.PnP

"Device Console" utility class. Managed wrapper for common SetupAPI actions.

public static class Devcon

Inheritance ObjectDevcon

Remarks:

https://docs.microsoft.com/en-us/windows-hardware/drivers/install/setupapi

Methods

Creates a virtual device node (hardware ID) in the provided device class.

public static bool Create(string className, Guid classGuid, string node)

Parameters

className String
The device class name.

classGuid Guid
The GUID of the device class.

node String
The node path terminated by two null characters.

Returns

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)

Parameters

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.

Caution

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)

Parameters

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.

Returns

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)

Parameters

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.

Returns

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)

Parameters

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.

Returns

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)

Parameters

target Guid
The device class GUID.

hardwareId String
The hardware ID to search for.

Returns

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)

Parameters

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.

Returns

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)

Parameters

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.

Returns

True if found, false otherwise.

Invokes the installation of a driver via provided .INF file.

public static bool Install(string fullInfPath, ref Boolean rebootRequired)

Parameters

fullInfPath String
An absolute path to the .INF file to install.

rebootRequired Boolean&
True if a machine reboot is required, false otherwise.

Returns

True on success, false otherwise.

Instructs the system to re-enumerate hardware devices.

public static bool Refresh()

Returns

True on success, false otherwise.

Instructs the system to re-enumerate hardware devices including disconnected ones.

public static bool RefreshPhantom()

Returns

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)

Parameters

classGuid Guid
The device class GUID.

instanceId String
The instance ID.

Returns

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)

Parameters

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.

Returns

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)

Parameters

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.

Returns

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.