@hong_zhong said:
What I don’t understand is that when an exception occurs, the contents of the registry are only deviceInterfaceguid missing, and other contents are normal. And In this case, hot plugging does not solve the problem.
It’s blindingly simple, really … and if you want to see it “play by play” then bring up ProcessMonitor and monitor for registry changes …
VMWare has a list of registry entries that are associated with a USB device, call them A, B, C and D and they go in locations 1, 2, 3 and 4. Those are registry entries that the OS uses to determine if a USB device is “there” or not. If the OS sees A, B, C and D at locations 1, 2, 3 and 4 then you have something in the device manager, if not then you don’t. The OS normally writes those entries when the driver is installed, and it also checks ONLY ON DRIVER LOAD (this is a key point, please reread those four words, repeat them to yourself, tell them to your spouse, sing them to your children, write them on your forearm) for a device interface GUID in the WCID extended descriptor. If it finds that GUID then it will write E at location 5 (which happens to be your GUID)
When WMWare does the “switch” it knows about A, B, C and D and stores them off, then removes them from the registry; they are gone. WMWare triggers a PnP renumeration (same as you do if you RClick on the top of the Device Manager tree and press “scan for new hardware”), the OS notices that A and B are now gone and removes the driver from PnP, same as if you had pressed “uninstall driver/ all” from the menu. The OS cleans up C, D and E. WMWare adds the VID/ PID of your device to it’s little tunnel driver (max of two devices, unfortunately), adds A and B to the target VM and triggers a renumeration; the target VM OS installs the driver (remember that little song? check your forearm …) and adds the GUID E to the registry.
Now it’s time for the switch back; VMWare removes A, B, C and D from the target VM OS and triggers a renumeration (removing that device), adds A, B, C and D to the host OS and again triggers a renumeration; the OS “sees” the device and it’s back in the Device Manager. Here’s the key point: VMWare knows absolutely nothing about E, the GUID. Not a bit, and won’t ever copy it … so when the OS cleans up after the first switch, that GUID is gone. Ask your spouse, what is the only time when that GUID ‘E’ will be read by the OS and written to the registry? If your children tell you “when the driver is loaded” then you know why after a “switch” the GUID is gone and only A, B, C and D remain … and if you check your forearm you’ll know why hot plugging won’t work either …
Again, bring up ProcessMonitor on the host and target VM, have it monitor for registry changes and you can see the action unfold …