2,640
社区成员
发帖
与我相关
我的任务
分享
for /f "tokens=2 delims==" %%a in ('wmic LogicalDisk where "DriveType='2'" get DeviceID /value') do (
echo %%a
// 遍历盘符
void CGetBusRelationshipHandle::getRegistryDiskInfo()
{
HKEY hKey; //定义有关的hKey,在查询结束时要关闭。
LPCTSTR path = "SYSTEM\\CurrentControlSet\\Services\\disk\\Enum";
LONG return0 = ( ::RegOpenKeyEx( HKEY_LOCAL_MACHINE, path, 0, KEY_READ, &hKey ) );
if ( return0 != ERROR_SUCCESS )
{
int err = GetLastError();
// MessageBox( "错误:无法打开有关的键!" );
cout << "错误:无法打开有关的键!" << endl;
}
TCHAR portName[ 255 ], commName[ 255 ];
DWORD dwLong, dwSize;
int i = 0;
while ( 1 )
{
dwLong = dwSize = sizeof( portName ) / sizeof( TCHAR );
if ( ::RegEnumValue( hKey, i, portName, &dwLong, NULL, NULL, ( PUCHAR )commName, &dwSize ) == ERROR_NO_MORE_ITEMS )
{
break;
}
else
{
mapDevice.insert( make_pair( strToLower(commName), portName ) );
}
i++;
}
//cout << commName << endl;
}
deviceDesc = DriverNameToDeviceDesc( driverKeyName, deviceID, strChild );
MAPDEVICE::iterator iter = mapDevice.find( strChild );
if ( iter != mapDevice.end() )
#include "stdafx.h"
using namespace std;
struct {
UINT type; LPCSTR name;
} DriveTypeFlags [] = {// GetDriveType返回码与人可读字符串对照表
{DRIVE_UNKNOWN ,"未知" },
{DRIVE_NO_ROOT_DIR ,"无效路经" },
{DRIVE_REMOVABLE ,"可移动" },
{DRIVE_FIXED ,"固定" },
{DRIVE_REMOTE ,"网络驱动器" },
{DRIVE_CDROM ,"CD-ROM" },
{DRIVE_RAMDISK ,"随机存取磁盘"},
{0 , NULL },
};
int _tmain() {
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) {
cerr << _T("Fatal Error: MFC initialization failed") << endl;
return -1;
}
// 获取逻辑驱动器字符串- a:\<null>b:\<null>c:\<null>...z:\<null><null>
// 还可以用GetLogicalDrives以位图形式代替字符串形式获取信息
TCHAR buf[200];
DWORD len = GetLogicalDriveStrings(sizeof(buf)/sizeof(TCHAR),buf);
string msg = "逻辑驱动器:\n";
for (TCHAR* s=buf; *s; s+=_tcslen(s)+1) {
LPCTSTR sDrivePath = s;
msg += sDrivePath;
msg += " ";
UINT uDriveType = GetDriveType(sDrivePath);
for (int i=0; DriveTypeFlags[i].name; i++) {
if (uDriveType == DriveTypeFlags[i].type) {
msg += DriveTypeFlags[i].name;
break;//
}
}
msg += '\n';
}
cout << msg.c_str();
return 0;
}