DCSIMG
Verify Installation of a custom device using C# - Asaf Shelly

Verify Installation of a custom device using C#

Published Tuesday, March 09, 2010 5:24 PM

Hi all,

Using my WinUSB C# component, I also needed to automatically install the driver if it is not already installed. The INF file defines a new device class by its GUID. This means that the class does not exist on the machine if the device is not installed.

Here is the code:

[DllImport("setupapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern bool SetupDiGetClassDescription(ref Guid ClassGuid,
StringBuilder classDescription, Int32 ClassDescriptionSize, ref UInt32 RequiredSize);


public static bool IsDeviceClassInstalled(string deviceClassGuid)
{
   return (IsDeviceClassInstalled(new Guid(deviceClassGuid)));
}

public static bool IsDeviceClassInstalled(Guid deviceClassGuid)
{
   StringBuilder deviceClassDescription = new StringBuilder(256);
   UInt32 retLength = 0;
   SetupDiGetClassDescription(ref deviceClassGuid, deviceClassDescription, deviceClassDescription.Capacity, ref retLength);
   return (deviceClassDescription.Length > 0);
}

 

http://blogs.microsoft.co.il/blogs/asafshelly/archive/2009/12/29/winusb-net-component.aspx

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: