实现安全删除硬件(USB Mass Storage device)? 我查了很多文档,没有找到资料,似乎不同的操作系统有不同的做法,也没有什么通用标准。我想问的是:在windows程序中怎样实现安全删除硬件,windows 发送了什么命令?(比如:SCSI 命令?或者别的什么?)Any source code? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://community.csdn.net/Expert/topic/2948/2948874.xml?temp=.8924982 http://community.csdn.net/Expert/TopicView3.asp?id=2948874 删除usb设备:#include <tchar.h>#include <stdio.h>#include <windows.h>#include <devguid.h>#define DWORD_PTR DWORD#define ULONG_PTR DWORDextern "C" { #include "hidsdi.h" }// 需加入hid.lib#include <setupapi.h>// 需加入setupapi.lib#include <regstr.h>#include <winbase.h>#include <cfgmgr32.h>// 需要加入cfgmgr32.lib#include <initguid.h>//#include <usbiodef.h>DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED);#define GUID_CLASS_USB_DEVICE GUID_DEVINTERFACE_USB_DEVICEint main(int argc, _TCHAR* argv[]){ HDEVINFO hDevInfo; SP_DEVINFO_DATA DeviceInfoData; DWORD i; //-------------------------------------------------------------------------- // 获取设备信息 hDevInfo = SetupDiGetClassDevs((LPGUID)&GUID_CLASS_USB_DEVICE, 0, // Enumerator 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE ); if (hDevInfo == INVALID_HANDLE_VALUE) { // 查询信息失败 printf("ERROR - SetupDiGetClassDevs()"); return 1; } //-------------------------------------------------------------------------- // 枚举每个USB设备 DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); for (i=0;SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData);i++) { LPTSTR buffer = NULL; PVOID buffer2 = NULL; DWORD buffersize = 0; ULONG len; CONFIGRET cr; PNP_VETO_TYPE pnpvietotype; CHAR vetoname[MAX_PATH]; ULONG ulStatus; ULONG ulProblemNumber; cr = CM_Get_DevNode_Status( &ulStatus, &ulProblemNumber, DeviceInfoData.DevInst, 0); if ( CR_SUCCESS == cr ) { printf("OK - CM_Get_DevNode_Status()[%d]\n", cr); printf("OK - CM_Get_DevNode_Status() sts [%x]\n", ulStatus); printf("OK - CM_Get_DevNode_Status() pro [%x]\n", ulProblemNumber); } else { printf("ERROR - CM_Get_DevNode_Status()[%d]\n", cr); printf("ERROR - CM_Get_DevNode_Status()[%d]\n", GetLastError()); } // DN_DISABLEABLE or DN_REMOVABLE if ((DN_DISABLEABLE & ulStatus ) != 0 ) { printf("HAS - DN_DISABLEABLE()[%x]\n", DN_DISABLEABLE & ulStatus); } else { continue; } if ((DN_REMOVABLE & ulStatus ) != 0 ) { printf("HAS - DN_REMOVABLE()[%x]\n", DN_REMOVABLE & ulStatus); } else { continue; } len = MAX_PATH; // pnpvietotype = PNP_VetoDevice; cr = CM_Request_Device_Eject( DeviceInfoData.DevInst, &pnpvietotype, vetoname, len, 0 ); if ( CR_SUCCESS == cr ) { printf("OK - CM_Request_Device_Eject()[%d]\n", cr); } else { printf("ERROR - CM_Request_Device_Eject()[%d]\n", cr); printf("ERROR - CM_Request_Device_Eject()[%d]\n", GetLastError()); } } if ( GetLastError()!=NO_ERROR && GetLastError()!=ERROR_NO_MORE_ITEMS ) { // Insert error handling here. return 1; } // Cleanup SetupDiDestroyDeviceInfoList(hDevInfo); return 0;} http://community.csdn.net/Expert/topic/4211/4211978.xml?temp=.5731165 提示 谁能够给我一个正确的等价表达式? 关于 调用 windows api 的通用颜色对话框 简单问题,CMap类,是否是线程安全的? 有个简单的错误处理的问题想咨询一下 请问各位前辈,计算机系的女生如何在计算机业混? 问简单问题 在一个函数里怎么调用新建的dialg 问题解决后的反思,不明白,请指点迷津 vs2005调用matlab生成的com组件 听说到灌水乐园来可以长可用分,是真的吗?? 问大家一个关于位图的问题 关于Windows MediaPlayer控件的版本 和 控件中控制函数的问题
#include <stdio.h>
#include <windows.h>
#include <devguid.h>#define DWORD_PTR DWORD
#define ULONG_PTR DWORD
extern "C" {
#include "hidsdi.h"
}
// 需加入hid.lib#include <setupapi.h>
// 需加入setupapi.lib#include <regstr.h>
#include <winbase.h>#include <cfgmgr32.h>
// 需要加入cfgmgr32.lib#include <initguid.h>
//#include <usbiodef.h>
DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE,
0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED);
#define GUID_CLASS_USB_DEVICE GUID_DEVINTERFACE_USB_DEVICEint main(int argc, _TCHAR* argv[])
{
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
DWORD i; //--------------------------------------------------------------------------
// 获取设备信息
hDevInfo = SetupDiGetClassDevs((LPGUID)&GUID_CLASS_USB_DEVICE,
0, // Enumerator
0,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE );
if (hDevInfo == INVALID_HANDLE_VALUE)
{
// 查询信息失败
printf("ERROR - SetupDiGetClassDevs()");
return 1;
}
//-------------------------------------------------------------------------- // 枚举每个USB设备
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for (i=0;SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData);i++)
{
LPTSTR buffer = NULL;
PVOID buffer2 = NULL;
DWORD buffersize = 0;
ULONG len;
CONFIGRET cr;
PNP_VETO_TYPE pnpvietotype;
CHAR vetoname[MAX_PATH];
ULONG ulStatus;
ULONG ulProblemNumber; cr = CM_Get_DevNode_Status( &ulStatus,
&ulProblemNumber,
DeviceInfoData.DevInst,
0);
if ( CR_SUCCESS == cr )
{
printf("OK - CM_Get_DevNode_Status()[%d]\n", cr);
printf("OK - CM_Get_DevNode_Status() sts [%x]\n", ulStatus);
printf("OK - CM_Get_DevNode_Status() pro [%x]\n", ulProblemNumber);
}
else
{
printf("ERROR - CM_Get_DevNode_Status()[%d]\n", cr);
printf("ERROR - CM_Get_DevNode_Status()[%d]\n", GetLastError());
}
// DN_DISABLEABLE or DN_REMOVABLE
if ((DN_DISABLEABLE & ulStatus ) != 0 )
{
printf("HAS - DN_DISABLEABLE()[%x]\n", DN_DISABLEABLE & ulStatus);
}
else
{
continue;
}
if ((DN_REMOVABLE & ulStatus ) != 0 )
{
printf("HAS - DN_REMOVABLE()[%x]\n", DN_REMOVABLE & ulStatus);
}
else
{
continue;
} len = MAX_PATH;
// pnpvietotype = PNP_VetoDevice;
cr = CM_Request_Device_Eject(
DeviceInfoData.DevInst,
&pnpvietotype,
vetoname,
len,
0
);
if ( CR_SUCCESS == cr ) {
printf("OK - CM_Request_Device_Eject()[%d]\n", cr);
} else {
printf("ERROR - CM_Request_Device_Eject()[%d]\n", cr);
printf("ERROR - CM_Request_Device_Eject()[%d]\n", GetLastError());
} }
if ( GetLastError()!=NO_ERROR &&
GetLastError()!=ERROR_NO_MORE_ITEMS )
{
// Insert error handling here.
return 1;
}
// Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo); return 0;
}