USB Device Status Change Tool

Automatically recognize and print PnP for USB devices, and select a specific device from the list and double-click on the device to force the device to stop. Double-clicking a device is a tool that can be changed again.

It’s a tool that came to save you, trying to get rid of all USB devices that bother. = _ =;

Source-Code:
Download deviceinfo_cs_ver full source code

const int DIGCF_PRESENT = 0x2;
const int DIGCF_ALLCLASSES = 0x4;
const int SPDRP_DEVICEDESC = 0x0;
const int SPDRP_CLASS = 0x7;
const int SPDRP_FRIENDLYNAME = 0xC;
const int CR_SUCCESS = 0x0;
const int DN_STARTED = 0x8;
const int CM_PROB_DISABLED = 0x16;
[StructLayout(LayoutKind.Sequential)]
struct SP_DEVINFO_DATA
{
public uint cbSize;
public Guid classGuid;
public IntPtr devInst;
public ulong reserved;
};
[DllImport("setupapi.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SetupDiGetClassDevs(
IntPtr classGuid,
[MarshalAs(UnmanagedType.LPTStr)] string enumerator,
IntPtr parentWindow,
uint flags
);
[DllImport("setupapi.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SetupDiDestroyDeviceInfoList(
IntPtr devInfo
);
[DllImport("setupapi.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, SetLastError = true)]
static extern Boolean SetupDiEnumDeviceInfo(
IntPtr deviceInfoSet,
int memberIndex,
ref SP_DEVINFO_DATA deviceInfoData
);
[DllImport("setupapi.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, SetLastError = true)]
static extern bool SetupDiGetDeviceRegistryProperty(
IntPtr deviceInfoSet,
ref SP_DEVINFO_DATA deviceInfoData,
uint property,
out UInt32 propertyRegDataType,
IntPtr propertyBuffer,
uint propertyBufferSize,
out UInt32 requiredSize
);
[DllImport("setupapi.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, SetLastError = true)]
static extern int CM_Get_DevNode_Status(
ref UInt32 status,
ref UInt32 probNum,
IntPtr devInst,
int flags
);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (this.textBox1.Text.Length == 0)
{
return;
}
this.listView1.Items.Clear();
string enumerator = this.textBox1.Text;
IntPtr devInfo = SetupDiGetClassDevs(IntPtr.Zero, enumerator, IntPtr.Zero, DIGCF_PRESENT | DIGCF_ALLCLASSES);
if (devInfo.ToInt32() == -1)
{
return;
}
for (int index = 0; ; ++index)
{
SP_DEVINFO_DATA devInfoData = new SP_DEVINFO_DATA();
devInfoData.devInst = (IntPtr)0;
devInfoData.classGuid = Guid.Empty;
devInfoData.reserved = 0;
devInfoData.cbSize = 28; // x86에서는 28바이트입니다. //  x86, click 28.
if (SetupDiEnumDeviceInfo(devInfo, index, ref devInfoData) == false)
{
break;
}
UInt32 regType = 0;
uint requiredSize = 0;
uint size = 256;
IntPtr classNameBuffer = new IntPtr();
classNameBuffer = Marshal.AllocHGlobal((int)size);
SetupDiGetDeviceRegistryProperty(devInfo, ref devInfoData, SPDRP_CLASS, out regType, classNameBuffer, size, out requiredSize);
string className = Marshal.PtrToStringAuto(classNameBuffer);
IntPtr descriptionBuffer = new IntPtr();
descriptionBuffer = Marshal.AllocHGlobal((int)size);
SetupDiGetDeviceRegistryProperty(devInfo, ref devInfoData, SPDRP_DEVICEDESC, out regType, descriptionBuffer, size, out requiredSize);
string description = Marshal.PtrToStringAuto(descriptionBuffer);
string statusString = "";
UInt32 status = 0, probNum = 0;
int ret = CM_Get_DevNode_Status(ref status, ref probNum, devInfoData.devInst, 0);
if (ret == CR_SUCCESS)
{
if ((status & DN_STARTED) == DN_STARTED)
{
statusString = "사용 / Use";
}
else
{
if (probNum == CM_PROB_DISABLED)
{
statusString = "사용 안함 / Disable";
}
else
{
statusString = "문제 코드 / Problem code: " + probNum.ToString();
}
}
}
else
{
statusString = "상태 조회 실패 / Health check failed";
}
var itemArray = new String[] { className, description, statusString };
this.listView1.Items.Add(new ListViewItem(itemArray));
}
SetupDiDestroyDeviceInfoList(devInfo);
}

Please excuse me if the source is messy/ Sorry for bad english.

Well, thanks!