如何获取系统连接了几个硬盘设备

charleswu82 2007-04-09 12:28:10
如何获取系统连接了几个硬盘设备
如:"\\\\.\\PHYSICALDRIVE0"之类
要求能检测硬盘,U盘,光驱
...全文
671 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
magicyang87 2007-04-21
  • 打赏
  • 举报
回复
GetVolumeInfomation吧,枚举系统硬盘,然后计数就行了
charleswu82 2007-04-15
  • 打赏
  • 举报
回复
up
charleswu82 2007-04-14
  • 打赏
  • 举报
回复
up
charleswu82 2007-04-10
  • 打赏
  • 举报
回复
按照
http://www.auyou.com/myweb/blog-1/wzinfo.asp?c_uid=antiboss&auto_id=75189
在VC6.0下配置了Platform SDK
----------------------------------------------------------------------------------
如何在VC6.0下配置SDK:
(假设SDK安装目录:E:\PROGRAM FILES\MICROSOFT PLATFORM SDK FOR WINDOWS XP SP2)
1.
Tools/Options/Directories/Include files
在列表的开始追加目录
E:\PROGRAM FILES\MICROSOFT PLATFORM SDK FOR WINDOWS XP SP2\INCLUDE
原来的mfc的include文件 //是原来自带那个移动到上面那个下面吗?
...
在列表的最后追加目录
E:\PROGRAM\MICROSOFT PLATFORM SDK\INCLUDE\ATL //我找不到!!!
E:\PROGRAM\MICROSOFT PLATFORM SDK\INCLUDE\CRT //我找不到!!!

2.
Tools/Options/Directories/Library files
在列表的最后位置追加目录
E:\PROGRAM FILES\MICROSOFT PLATFORM SDK FOR WINDOWS XP SP2\LIB

3.
Project/Settings.../Link/Object/library modules:
psapi.lib

4.
程序中加入
#include "psapi.h" // For EnumProcesses
-------------------------------------------------------------------------------------

这是我的代码:
#include <windows.h>
#include <setupapi.h>
#include <stdio.h>
#include "psapi.h" //按照上面所说的加入的
#include <devguid.h> //for GUID

HDEVINFO DoDeviceEnum( const GUID * InterfaceClassGuid )
/*
Routine Description:
Retrieves the device information set that contains that contains
the devices of the specified class.
//列举特定类型的设备

Parameters:
InterfaceClassGuid - The interface class GUID.
//参数接口类的GUID

Return Value:
If the function succeeds, the return value is a handle to the
device information set.
//成功返回设备信息集合的设备句柄

If the function fails, the return value is zero.
//失败返回0
*/
{
HDEVINFO DeviceInfoSet;
HDEVINFO NewDeviceInfoSet;

// Create a device information set that will be the container for
// the device interfaces.
//建立设备信息集来存放设备接口

DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL);

if(DeviceInfoSet == INVALID_HANDLE_VALUE)
{
printf("CreateDeviceInfoList failed: %d\n", GetLastError());
return 0;
}

// Retrieve the device information set for the interface class.

NewDeviceInfoSet = SetupDiGetClassDevsEx( InterfaceClassGuid,
NULL,
NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE,
DeviceInfoSet,
NULL,
NULL
);

if(NewDeviceInfoSet == INVALID_HANDLE_VALUE)
{
printf( "SetupDiGetClassDevsEx failed: %d\n", GetLastError() );
return 0;
}

return NewDeviceInfoSet;
}

void main()
{
HDEVINFO hMyDev = DoDeviceEnum((LPGUID) &GUID_DEVCLASS_DISKDRIVE);
/*

GUID_DEVCLASS_FDC软盘控制器

GUID_DEVCLASS_DISPLAY显示卡

GUID_DEVCLASS_CDROM光驱

GUID_DEVCLASS_KEYBOARD键盘

GUID_DEVCLASS_COMPUTER计算机

GUID_DEVCLASS_SYSTEM系统

GUID_DEVCLASS_DISKDRIVE磁盘驱动器

GUID_DEVCLASS_MEDIA声音、视频和游戏控制器

GUID_DEVCLASS_MODEMMODEM

GUID_DEVCLASS_MOUSE鼠标和其他指针设备

GUID_DEVCLASS_NET网络设备器

GUID_DEVCLASS_USB通用串行总线控制器

GUID_DEVCLASS_FLOPPYDISK软盘驱动器

GUID_DEVCLASS_UNKNOWN未知设备

GUID_DEVCLASS_SCSIADAPTERSCSI 和 RAID 控制器

GUID_DEVCLASS_HDCIDE ATA/ATAPI 控制器

GUID_DEVCLASS_PORTS端口(COM 和 LPT)

GUID_DEVCLASS_MONITOR监视器



*/

//如何输出诸如"\\\\.\\PHYSICALDRIVE0"的指向物理硬盘的字串

}

报错如下:
Linking...
s.obj : error LNK2001: unresolved external symbol __imp__SetupDiGetClassDevsExA@28
s.obj : error LNK2001: unresolved external symbol __imp__SetupDiCreateDeviceInfoList@8
Debug/test4.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

test4.exe - 3 error(s), 0 warning(s)
pomelowu 2007-04-09
  • 打赏
  • 举报
回复
Enumerating Current Devices
Applications can use the SetupDiGetClassDevsEx function to retrieve the list of current devices. The following example function demonstrates how to retrieve this list.



#include <windows.h>
#include <setupapi.h>

HDEVINFO DoDeviceEnum( const GUID * InterfaceClassGuid )
/*
Routine Description:
Retrieves the device information set that contains that contains
the devices of the specified class.

Parameters:
InterfaceClassGuid - The interface class GUID.

Return Value:
If the function succeeds, the return value is a handle to the
device information set.

If the function fails, the return value is zero.
*/
{
HDEVINFO DeviceInfoSet;
HDEVINFO NewDeviceInfoSet;

// Create a device information set that will be the container for
// the device interfaces.

DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL);

if(DeviceInfoSet == INVALID_HANDLE_VALUE)
{
printf("CreateDeviceInfoList failed: %d\n", GetLastError());
return 0;
}

// Retrieve the device information set for the interface class.

NewDeviceInfoSet = SetupDiGetClassDevsEx( InterfaceClassGuid,
NULL,
NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE,
DeviceInfoSet,
NULL,
NULL
);

if(NewDeviceInfoSet == INVALID_HANDLE_VALUE)
{
printf( "SetupDiGetClassDevsEx failed: %d\n", GetLastError() );
return 0;
}

return NewDeviceInfoSet;
}

After you have registered to receive device interface notification messages, you can call this function to obtain a device information set that contains the current list of device interfaces. When you receive a DBT_DEVICEARRIVAL event, you can use the SetupDiOpenDeviceInterface function to add the device interface to the device information set. When you receive a DBT_DEVICEREMOVECOMPLETE event, you can use the SetupDiDeleteDeviceInterfaceData function to delete the device interface from the device information set.
步履人生 2007-04-09
  • 打赏
  • 举报
回复
using shell

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧