现在有一个USB设备总是自己死掉~~
除非拔下USB设备,重新插上!
请问有没有方法可以用代码实现拔插的效果(在WINDOWS下)
最好是用VB~
请高人指点一下
------解决方案--------------------
这个是可以做到的
BOOL CHubHelper::Hub_PlugOff(LPCTSTR hubName, DWORD PortIndex)
{
BOOL Success(FALSE);
SECURITY_ATTRIBUTES SA={0};
SA.nLength = sizeof(SECURITY_ATTRIBUTES);
HANDLE HubHandle = CreateFile(hubName, GENERIC_WRITE, FILE_SHARE_WRITE, &SA, OPEN_EXISTING, 0, NULL);
if( HubHandle != INVALID_HANDLE_VALUE )
{
DWORD BytesReturned = 0;
ULONG ConnectedHub = PortIndex;
Success = DeviceIoControl(HubHandle, IOCTL_USB_HUB_CYCLE_PORT, &ConnectedHub,sizeof(ConnectedHub), &ConnectedHub, sizeof(ConnectedHub), &BytesReturned, NULL);
CloseHandle(HubHandle);
}
return Success;
}