如何通过程序停用和安全删除系统托盘里的USB设备?
我有一个设备经常会在PC上作插拔操作,插上后会系统托盘会识别为USb设备,每次手动safely remove太麻烦了,能不能通过程序来自动safely remove,这样就简单多了,请高手给个简单一点的例子看看,多谢!
[解决办法]
你看一下系统的Hotplug.dll导出的函数就知道了。
Microsoft (R) COFF Binary File Dumper Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
Dump of file C:\windows\system32\hotplug.dll
File Type: DLL
Section contains the following exports for hotplug.DLL
0 characteristics
411076E8 time date stamp Wed Aug 04 13:40:56 2004
0.00 version
1 ordinal base
15 number of functions
15 number of names
ordinal hint RVA name
1 0 00005A64 CPlApplet
2 1 0000276C CreateLocalServerW
12 2 00002659 DllCanUnloadNow
13 3 0000266A DllGetClassObject
14 4 0000268B DllRegisterServer
15 5 0000269F DllUnregisterServer
3 6 000056B4 HotPlugDeviceTree
4 7 000059D1 HotPlugDriverBlockedW
5 8 00005746 HotPlugEjectDevice <----------
6 9 00005B38 HotPlugEjectVetoedW
7 A 00005B68 HotPlugHibernateVetoedW
8 B 00005B20 HotPlugRemovalVetoedW
9 C 0000584A HotPlugSafeRemovalNotificationW <---------
10 D 00005B50 HotPlugStandbyVetoedW
11 E 00005B80 HotPlugWarmEjectVetoedW
Summary
3000 .data
2000 .reloc
F000 .rsrc
11000 .text
[解决办法]
弹出USB设备:
void PopupUSBDevice()
{
char strSystemDirectory[256];
GetSystemDirectory( strSystemDirectory, 256 );
CString strTemp = strSystemDirectory;
strTemp += "\\rundll32.exe shell32.dll,Control_RunDLL hotplug.dll ";
WinExec( strTemp, SW_SHOW );
}
[解决办法]
使用DDK可以很好的删除USB设备,你可以指定盘符进行删除,也可以指定GUID(就是设备号)进行删除。我们以前都这是么做的,使用楼上的方法就不好了,结果全弹出来了。不好不好。
[解决办法]
楼上可否举个例子
------使用DDK可以很好的删除USB设备,你可以指定盘符进行删除,也可以指定GUID(就是设备号)进行删除。