Link to home
Start Free TrialLog in
Avatar of matelindonesia
matelindonesia

asked on

Shutdown and Eject USB Disk

Hi all,
Anyone can help me how to create a function to shutdown/eject USB Disk just what windows done by click Safely Remove Hardware Icon in systray. I wonder there's a function with drive parameter, examp: ShutDownUSB(driveletter: char)

Sirro
Avatar of robert_marquardt
robert_marquardt

The function is called CM_Request_Device_Eject and is located in the Config Manager API.
Get both Zips from http://www.sf.net/projects/jedi-apilib
In "Setup and Config Manager API" you will find an example precisely for what you want to do.
I've try the example code, and installed the JEDI component(JVCL and JCL), but why it always ask the JwaDbt unit?

FYI I used Jedi component ver 3.00

Thanks
Because this is the Jedi-Apilib which is a conversion of the Win32 API.
Add the path to the directory where you unpacked the jedi-apilib files to the library path of Delphi.
Also to the Setup API conversion.
Sorry, these files have no installer yet.
Avatar of matelindonesia

ASKER

Oke, I've add the library path for win32 api and Setup API Conversion, It works, but why whe it entered the FillDriveList procedure, excatly on GetDriveInstanceID procedure it raised EAccessViolation.
FYI I've code on WinXP OS with SP2, is it make any influence?
ASKER CERTIFIED SOLUTION
Avatar of robert_marquardt
robert_marquardt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks to robert_marquardt,

I finally got solution after looking for it since last year,
BRAVO ...!!!

:)

Regards
Sirro
For other readers:
The problem with the demo program was that i tested it only under Win 2000.
The bug in the Setup API conversion was Win XP specific. That resulted in the demo not being able to access the Setup API at all when compiled for Win XP.

I do know more about CM_Request_Device_Eject. Better not try to use it from a service.
There are numerous quirks in that API resulting in unwanted Surprise Removal dialogs popping up.
I got the same problem, how do I solve it? Please help.
Regards,
Maciek
The bug is in cfgmgr32.pas. I converted CM_Is_Version_Available and CM_Is_Version_Available_Ex, but these functions are not in cfgmgr32.dll.
Search for "CM_Is_Version_Available" and comment out *all* occurrences.
These functions are in fact a bad trick of MS Visual Studio. It uses cfgmgr.lib instead of cfmgr32.lib to link to the DLL and these functions
are implemented in the lib whereas most other functions are delegated to the DLL as usual.