Removable USB Devices
Yet another fun little Vista issue. I haven’t posted one of these in a while.
I’ve got a 128mb SD memory card and I wanted to transfer some stuff to it, so I plug it into the computer. The computer doesn’t recognize it for some reason – the drive letter is there, but it doesn’t show any device being there. “Hmm”, I think, “Maybe I didn’t safely remove the device last time”. So I right-click the drive and choose to safely remove it.
The SD card reader I have is mounted in a drive bay, and came with the computer. It has a number of readers – four of them – and Windows unmounted all of them. “Hmm”.
I put the SD card back in the reader, expecting the drive to re-appear, but no drive. “Hmm”.
Open up Device Manager, and I see a little yellow triangle next to the reader.
Open Properties, and here’s what it says:
Windows cannot use this hardware device because it has been prepared for “safe removal”, but it has not been removed from the computer. (Code 47)
I guess what it wants me to do is open up the computer and disconnect the reader from the motherboard. Thanks, but I’d rather not. A reboot would fix it, but being a bit stubborn I tell Windows to disable the device and then re-enable it. But Windows is on to this trick, and tells me I must reboot.
So a quick attempt to copy some files onto an SD card turns into a half hour distraction involving drivers and rebooting. If only there was an OS where this stuff just worked.
October 10th, 2007 at 10:41 pm
Not just Vista – Both XP and 2K does this to a user who has mistakenly clicked on the wrong “Safely remove USB Mass Storage Device – (Drive X:)” item on that little green ‘card’ icon. I’m on a hunt to find a solution, since as of my last acquisition, I have an array of 11 USB devices – drives and memory – plugged into my server. If I find something, I’ll post it back here, but don’t hold your breath. : )
March 31st, 2008 at 3:46 am
Since most SD card readers are plugged though a USB interface like this Radioshack one http://www.radioshack.com/sm-digital-concepts-sd-card-reader–pi-2280578.html I’m assuming yours is recognized like a USB storage. Right? Anyway, it is generally recommended http://support.microsoft.com/kb/310123 that you either UNPLUG the device physically or if it’s not acceptable – you HAVE to reboot a PC. So that’s not a problem but more of a warning message notifying you about the event and recommending you unplug the device once you told Windows that you want to remove it. That’s because of the CM_PROB_HELD_FOR_EJECT error that’s returned by the Device Manager. If you can’t remove it and don’t want to reboot, try ejecting the device by selecting the Eject command from the context menu for the removable drive in Windows Explorer tree (this will be above the Format command) . This however may lead to a warning message that reads
‘The device ‘Generic volume’ cannot be stopped because a program is still accessing it.’
This problem is listed as solved at http://support.microsoft.com/kb/305372 back in 09-Oct-2001 although it seems to exist at least on Windows XP SP2 so that you may get this error if you try to safely remove a USB device AFTER you’ve selected the Eject command from the context menu. If you read the error description it says that ‘You receive this error message although no program is accessing the device’. That is you can safely remove your device after that without getting a code 47 error. Moreover, if you look into ProcessExplorer and try to find a handle for the USBSTOR device you will not find any handles what may indicate that NOTHING in fact uses the device. If so, you may just unplug the device. There’s yet another option you can Eject your drive without getting the error specified above. This may however lead to the same issue with a warning notifying you about the need to unplug the device. Here what you could try:
1. Click Start|Control Panel|Administrative Tools|Computer Management or just click Start|Run and type compmgmt.msc then press Enter
2. In the Computer Management snap-in window opened navigate to Storage|Removable Storage|Libraries.
3. Find there your connected device, right-click it and select Eject
The device will be ejected silently.
4. Alternatively, open the same Storage|Removable Storage tree item and navigate to Media item
5. Locate your attached storage device and select Eject from the context menu. The media ejection wizard will start for you. Follow the steps to finish with device ejection procedure.
The problem here is that most device drivers cannot be restarted without rebooting a PC. Thus if you want to stop or restart the CD-ROM driver typing something like
net stop cdrom
won’t help as you’ll get the ‘The requested pause or stop is not valid for this service.’ message from the Service Control Manger. This is because this service/driver was made so that it doesn’t accept this command. That is such service is not marked as stoppable and eturns no sign on that when calling the http://msdn2.microsoft.com/en-us/library/ms686241.aspx SetServiceStatus function.
If you don’t want to mess this up in the future it’s probably better to disable the use of the device completely. I use that to prevent my user from using unwanted devices or just to prevent them from getting problems like that. The complex thing however is to configure who will be allowed to use this device and whose access will be forbidden. Partially this can be solved by using a paired technique where the workaround is to first use the ‘ifmember’ tool that evaluates the device security policy appliance at the user’s logon and apply the device blocking after that by calling the devcon tool from Windows DDK. However this adds some extra work to resolve issues when you need to make some exclusions based on the user environment. For example it’s not for every day use when you want your user to not have access to his WIFI device. For example we maintain a security policy when every guest user that comes into our office has some restricted access to our some part of our local network as well as a mail access to be able to communicate with colleagues. Sometimes you have to disable the use for mobile devices, or more importantly the write access to CD-ROM or FireWire attached HDD storage. This involves LOTS of work in scripting that evaluates events and parses multiple parameters including information from Active Directory as well as information that is unique for the single user. I spend weeks trying to build a reliable custom made solution but finally found an easy workaround for all my pressing needs. The answer was to use desktop management tool that allows configuring user computers based on the rules set. I tried several solutions but among all of them the most easy to use and lightweight one was Scriptlogic’s Desktop Authority which I currently use in my production environment. That tool allowed me to configure extensive device lockdown policies http://www.scriptlogic.com/desktop-authority-usb-device-lockdown.asp based on Active Directory information without the need to link something in GPMC. That allowed me to precisely configure device use from every single user using personalized security policies that depend on the environment state. For example if the user connects his cell phone to his notebook he will not be able to use it. However if he connects the phone to his desktop PC he may use it as I know that for his desktop PC I have special security lockdown rules that guarantee that no sensitive information will leak from our company. I found that device management should be controlled centrally involving the use of functionality available from Desktop Authority, system internal policies and some custom self-written solutions. It provides the best protection and helps me stay sure that I control the use of devices on every PC that logs into my domain.
By the way if you want to open the safely remove hardware dialog box programmatically, you can run
RUNDLL32.EXE SHELL32.DLL,Control_RunDLL HotPlug.dll