#include <windows.h>
#include <tchar.h>
#include <SetupAPI.h>
#include <cfgmgr32.h>
#pragma comment(lib, "cfgmgr32")
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE PrevInstance, LPSTR CmdLine, int CmdShow)
{
TCHAR* hid = _T("USB\Vid_0c76&Pid_0007\USB000000001"); // VID&PID 可在设备管理器中得到
HMACHINE hMachine = NULL;
DEVINST dnDevInst = NULL;
PDEVINST pdnDevInst_OUT = &dnDevInst;
if (CR_SUCCESS == CM_Locate_DevNode_Ex(pdnDevInst_OUT, hid, CM_LOCATE_DEVNODE_NORMAL, hMachine)) {
if (CR_SUCCESS == CM_Request_Device_Eject_Ex(dnDevInst, NULL, NULL, 0, 0, hMachine )){
MessageBox(NULL, _T("Eject success"), _T("info), 0);
}
}
return 0;
}