Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to force Windows to totally reinitialize an USB flash drive without unplug/plug in

253 views
Skip to first unread message

Zackmann

unread,
Sep 13, 2007, 3:36:30 AM9/13/07
to
I open an USB flash drive via CreateFile with PhysicalDrive{n} and
then change the data on disk completely, that means I crete different
partition sizes and file systems. Everything works fine and when I
unplug the drive after Im done and then plug it in again, there are no
problems at all. The drive is accessable, no errors occur and all
sizes and properties of the image are as I expected them.

But I didnt found a way to get this to work *without* unplug/insert
the USB flash drive on Windows XP. I tried every combination of
FSCTL_LOCK_VOLUME / FSCTL_UNLOCK_VOLUME, FSCTL_MOUNT_VOLUME /
FSCTL_DISMOUNT_VOLUME, On Windows Vista I was able to reinitialize the
drive with this funktions.

I also tried out removing and setting mountpoints again via
GetVolumeNameForVolumeMountPoint, DeleteVolumeMountPoint and
SetVolumeMountPoint. While these funktions worked fine (the
driveletter in windows explorer disapperead and then showed up again)
there was no reinitialization of the drive data itself. windows
explorer still displays the drive as "o Bytes / need to format".

After this I tried out BroadcastSystemMessage with WM_DEVICECHANGE and
DBT_DEVICEARRIVAL / DBT_DEVICEREMOVECOMPLETE with no success.

Finally I tried DeviceIoControl with IOCTL_STORAGE_EJECT_MEDIA /
IOCTL_STORAGE_LOAD_MEDIA. Ironically Im able to remove the drive via
IOCTL_STORAGE_EJECT_MEDIA, but I cant load it again via
IOCTL_STORAGE_LOAD_MEDIA. After the first command the drive is removed
from system, but after the second command it's still removed...

Is there a way to force windows xp to treat a connected flash drive
like it has just been connected to the system?

Thanks a lot for help

Zackmann

unread,
Sep 13, 2007, 7:04:30 AM9/13/07
to
Problem Update

There is a possibility to force windows xp to reinitialize the media
just the way I need it. Open "Control Panel", click "Performance and
Maintenance", "Administrative Tools", "Computer Management",
"Storage", "Removable Storage", "Libraries", then rightlick the flash
drive and select "inject". This will perform a reinitialization of the
drive and after that the drive is present in windows explorer with the
new file system and without errors. But I still dont't know what
activities are triggered on "inject". Someone can tell me? Which
funstion(s) from which DLL(s) or which api functions have to be called
to do the same as "inject" does?

Thank you very much

Kellie Fitton

unread,
Sep 13, 2007, 3:01:33 PM9/13/07
to


Hi,

What happens when you use the following APIs to refresh
the Windows shell ?

SHChangeNotify(SHCNE_DRIVEADD, SHCNF_PATH, L"G:\", NULL);

SHChangeNotify(SHCNE_DRIVEREMOVED, SHCNF_PATH, L"G:\", NULL);

SHChangeNotify(0, SHCNF_FLUSH, NULL, NULL);

http://msdn2.microsoft.com/en-us/library/ms647673.aspx

Kellie.


Zackmann

unread,
Sep 13, 2007, 6:37:55 PM9/13/07
to
Hi Kellie,

> What happens when you use the following APIs to refresh
> the Windows shell ?
>
> SHChangeNotify(SHCNE_DRIVEADD, SHCNF_PATH, L"G:\", NULL);
>
> SHChangeNotify(SHCNE_DRIVEREMOVED, SHCNF_PATH, L"G:\", NULL);
>
> SHChangeNotify(0, SHCNF_FLUSH, NULL, NULL);

Using this functions looks pretty much like calling
FSCTL_DISMOUNT_VOLUME to me. After using SHCNE_DRIVEREMOVED the symbol
and driveletter disappear from windows explorer and then, after using
SHCNE_DRIVEADD, are showing up again. But Windows does not update its
internal data. If the drive was not accessable before the calls it
still isn't after the calls. Looks like SHCNF_FLUSH does not change
this behaviour.

Thank you for the hint though :)

Uwe

Uwe Sieber

unread,
Sep 20, 2007, 3:13:58 AM9/20/07
to

I don't know if this really works but another playground
are configuration manager functions (CM_xxxx).
Check out the DEVCON sample that comes with the DDK/WDK.

When you deactivate the disk device and the reactivate
it, then the drive partitioning should be checked again
by Windows.


Greetings from Germany

Uwe

0 new messages