Verify Installation of a custom device using C#

March 9, 2010

no comments

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

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*