使用Win32 API安全地删除一个USB驱动器?

时间:2023-01-26 21:39:00

How do I remove a USB drive using the Win32 API? I do a lot of work on embedded systems and on one of these I have to copy my programs on a USB stick and insert it into the target hardware.

如何使用Win32 API删除USB驱动器?我在嵌入式系统上做了很多工作,其中之一就是把我的程序复制到USB上,然后插入目标硬件。

Since I mostly work on the console I don't like to use the mouse and click on the small task-bar icon hundred times a day.

由于我主要在控制台工作,所以我不喜欢每天使用鼠标点击小任务栏图标上百次。

I'd love to write a little program to do exactly that so I can put it into my makefiles, but I haven't found any API call that does the same thing.

我很想写一个小程序来实现这一点,这样我就可以把它放到我的makefile中,但是我还没有找到任何做同样事情的API调用。

Any ideas?

什么好主意吗?

6 个解决方案

#1


17  

You can use the CM_Request_Device_Eject() function as well as some other possibilities. Consult the following projects and articles:

您可以使用CM_Request_Device_Eject()函数以及其他一些可能性。咨询以下项目和条款:

DevEject: Straightforward. http://www.withopf.com/tools/deveject/

DevEject:简单。http://www.withopf.com/tools/deveject/

A useful CodeProject article: http://www.codeproject.com/KB/system/RemoveDriveByLetter.aspx

一个有用的代码项目文章:http://www.codeproject.com/KB/system/RemoveDriveByLetter.aspx

#2


15  

See Microsoft Knowledge Base article Q165721: http://support.microsoft.com/kb/165721 -- includes full C source code

参见Microsoft知识库文章Q165721: http://support.microsoft.com/kb/165721——包含完整的C源代码

#3


4  

It looks like Sync lets you specify -e to eject removable drives. While not a win32 API, you could probably just call sync -e [drive_letter] from your makefile.

看起来同步允许你指定-e来弹出可移动驱动器。虽然不是win32 API,但您可以从makefile中调用sync -e [drive_letter]。

#4


3  

This article and sample should do the trick: http://support.microsoft.com/default.aspx?scid=kb;en-us;165721

本文和示例应该具有以下功能:http://support.microsoft.com/default.aspx?scid=kb;en-us;165721

#5


2  

Here is a technet article about removable storage media. Look for DismountNtmsMedia.

这是一篇关于可移动存储介质的technet文章。寻找DismountNtmsMedia。

#6


0  

Here's a solution in Delphi, that I've modified and put into a service for use in a very large enterprise. Go to: link text

在Delphi中有一个解决方案,我对它进行了修改,并将其放入服务中,以便在大型企业中使用。去:链接文本

Look for "scapi (Setup & Config Manager API)", and download it. There will be a demo program called USBView that will get you on your way. If you have Delphi, this also includes a TUSBDeviceTree component that you can use to gather information about a USB device when.

查找“scapi(设置和配置管理器API)”,下载它。将会有一个叫做USBView的演示程序,它会带你上路。如果您有Delphi,这还包括一个TUSBDeviceTree组件,您可以使用它来收集关于USB设备的信息。

Regards

问候

#1


17  

You can use the CM_Request_Device_Eject() function as well as some other possibilities. Consult the following projects and articles:

您可以使用CM_Request_Device_Eject()函数以及其他一些可能性。咨询以下项目和条款:

DevEject: Straightforward. http://www.withopf.com/tools/deveject/

DevEject:简单。http://www.withopf.com/tools/deveject/

A useful CodeProject article: http://www.codeproject.com/KB/system/RemoveDriveByLetter.aspx

一个有用的代码项目文章:http://www.codeproject.com/KB/system/RemoveDriveByLetter.aspx

#2


15  

See Microsoft Knowledge Base article Q165721: http://support.microsoft.com/kb/165721 -- includes full C source code

参见Microsoft知识库文章Q165721: http://support.microsoft.com/kb/165721——包含完整的C源代码

#3


4  

It looks like Sync lets you specify -e to eject removable drives. While not a win32 API, you could probably just call sync -e [drive_letter] from your makefile.

看起来同步允许你指定-e来弹出可移动驱动器。虽然不是win32 API,但您可以从makefile中调用sync -e [drive_letter]。

#4


3  

This article and sample should do the trick: http://support.microsoft.com/default.aspx?scid=kb;en-us;165721

本文和示例应该具有以下功能:http://support.microsoft.com/default.aspx?scid=kb;en-us;165721

#5


2  

Here is a technet article about removable storage media. Look for DismountNtmsMedia.

这是一篇关于可移动存储介质的technet文章。寻找DismountNtmsMedia。

#6


0  

Here's a solution in Delphi, that I've modified and put into a service for use in a very large enterprise. Go to: link text

在Delphi中有一个解决方案,我对它进行了修改,并将其放入服务中,以便在大型企业中使用。去:链接文本

Look for "scapi (Setup & Config Manager API)", and download it. There will be a demo program called USBView that will get you on your way. If you have Delphi, this also includes a TUSBDeviceTree component that you can use to gather information about a USB device when.

查找“scapi(设置和配置管理器API)”,下载它。将会有一个叫做USBView的演示程序,它会带你上路。如果您有Delphi,这还包括一个TUSBDeviceTree组件,您可以使用它来收集关于USB设备的信息。

Regards

问候