SlavaI
Главный специалист
Offline
|
|
« : 12-09-2003 07:51 » |
|
На форуме уже возникали вопросы о получении информации об устройствах в Win2k/XP/2003. Вчера пришлось для теста написать програмку, которая собирает инфу об устройствах в системе. Вот выкладываю ее. Для получения инфы о конкретном типе устройств- смените в вызове DoDeviceEnum(GUID_DEVCLASS_CDROM); на свой GUID и смените в вызове SetupDiGetClassDevsEx параметр DIGCF_ALLCLASSES на DIGCF_PRESENT. Вывод программы перенаправляйте в файл, если все не влезает на экран( в случае вывода инфы обо всех устройствах так и будет). Файл devguid.h также привожу(но он есть в DDK и SDK). Линковать с Setupapi.lib. Компилить как UNICODE. Подобным же путем можно получить HANDLE устройства через GUID его интерфейса. #include "stdafx.h" #include <windows.h> #include <stdio.h> #include <Setupapi.h> #include "devguid.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; DWORD Err;
// Create a device information set that will be the container for // the device interfaces.
DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL); if(DeviceInfoSet == INVALID_HANDLE_VALUE) { Err = GetLastError(); wprintf( L"SetupDiCreateDeviceInfoList failed: %lx.\n", Err ); return 0; }
// Retrieve the device information set for the interface class.
NewDeviceInfoSet = SetupDiGetClassDevsEx( &InterfaceClassGuid, NULL, NULL, DIGCF_ALLCLASSES,//DIGCF_PRESENT /*| DIGCF_DEVICEINTERFACE*/, DeviceInfoSet, NULL, NULL );
/*NewDeviceInfoSet = SetupDiGetClassDevs(&InterfaceClassGuid, NULL, NULL, DIGCF_PRESENT /*| DIGCF_DEVICEINTERFACE);*/
if(NewDeviceInfoSet == INVALID_HANDLE_VALUE) { Err = GetLastError(); wprintf( L"SetupDiGetClassDevsEx failed: %lx.\n", Err ); return 0; }
return NewDeviceInfoSet; }
const int bsize = 10000; BYTE buffer[bsize]; int _tmain(int argc, _TCHAR* argv[]) { HDEVINFO devs; DWORD devIndex; _SP_DEVINFO_DATA devInfo; DWORD type; devs = DoDeviceEnum(GUID_DEVCLASS_BLUETOOTH);
if(devs == INVALID_HANDLE_VALUE) { wprintf(L"Error\n"); goto final; }
// // now enumerate them //
devInfo.cbSize = sizeof(devInfo); for(devIndex=0;SetupDiEnumDeviceInfo(devs,devIndex,&devInfo);devIndex++) { wprintf(L"/***********************/\n");
if(SetupDiGetDeviceRegistryProperty(devs,&devInfo,SPDRP_SERVICE , NULL, buffer,bsize,NULL)) wprintf(L"Driver: %S \n", buffer);
if(SetupDiGetDeviceRegistryProperty(devs,&devInfo,SPDRP_CLASSGUID , NULL, buffer,bsize,NULL)) wprintf(L"Class GUID: %S \n", buffer);
if(SetupDiGetDeviceRegistryProperty(devs,&devInfo,SPDRP_PHYSICAL_DEVICE_OBJECT_NAME, NULL, buffer,bsize,NULL)) wprintf(L"PDO: %S \n", buffer);
if(SetupDiGetDeviceRegistryProperty(devs,&devInfo,SPDRP_DEVTYPE, NULL, buffer,bsize,NULL)) wprintf(L"Device's type: 0x%X \n", buffer); if(SetupDiGetDeviceRegistryProperty(devs,&devInfo,SPDRP_ENUMERATOR_NAME, NULL, buffer,bsize,NULL)) wprintf(L"Device's enumerator: %S \n", buffer);
if(SetupDiGetDeviceRegistryProperty(devs,&devInfo,SPDRP_LOCATION_INFORMATION , NULL, buffer,bsize,NULL)) wprintf(L"Hardware location: %S \n", buffer);
if(SetupDiGetDeviceRegistryProperty(devs,&devInfo,SPDRP_DEVICEDESC , NULL, buffer,bsize,NULL)) wprintf(L"Device descrp.: %S \n", buffer);
if(SetupDiGetDeviceRegistryProperty(devs,&devInfo,SPDRP_FRIENDLYNAME , NULL, buffer,bsize,NULL)) wprintf(L"Friendly name: %S \n", buffer); if(SetupDiGetDeviceRegistryProperty(devs,&devInfo,SPDRP_UPPERFILTERS, NULL, buffer,bsize,NULL)) wprintf(L"Upper filter: %S \n", buffer);
if(SetupDiGetDeviceRegistryProperty(devs,&devInfo,SPDRP_LOWERFILTERS, NULL, buffer,bsize,NULL)) wprintf(L"Lower filter: %S \n", buffer);
if(SetupDiGetDeviceRegistryProperty(devs,&devInfo,SPDRP_MFG, NULL, buffer,bsize,NULL)) wprintf(L"Device manufacturer: %S \n", buffer); } wprintf(L"/***********************/\n");
final: if(devs != INVALID_HANDLE_VALUE) { SetupDiDestroyDeviceInfoList(devs); } return 0; }
/////////////////////////////////////////////////////////////// файл devguid.h /*++ BUILD Version: 0001 // Increment this if a change has global effects
Copyright (c) Microsoft Corporation. All rights reserved.
Module Name:
devguid.h
Abstract:
Defines GUIDs for device classes used in Plug & Play.
--*/
DEFINE_GUID( GUID_DEVCLASS_1394, 0x6bdd1fc1L, 0x810f, 0x11d0, 0xbe, 0xc7, 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f ); DEFINE_GUID( GUID_DEVCLASS_1394DEBUG, 0x66f250d6L, 0x7801, 0x4a64, 0xb1, 0x39, 0xee, 0xa8, 0x0a, 0x45, 0x0b, 0x24 ); DEFINE_GUID( GUID_DEVCLASS_61883, 0x7ebefbc0L, 0x3200, 0x11d2, 0xb4, 0xc2, 0x00, 0xa0, 0xc9, 0x69, 0x7d, 0x07 ); DEFINE_GUID( GUID_DEVCLASS_ADAPTER, 0x4d36e964L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_APMSUPPORT, 0xd45b1c18L, 0xc8fa, 0x11d1, 0x9f, 0x77, 0x00, 0x00, 0xf8, 0x05, 0xf5, 0x30 ); DEFINE_GUID( GUID_DEVCLASS_AVC, 0xc06ff265L, 0xae09, 0x48f0, 0x81, 0x2c, 0x16, 0x75, 0x3d, 0x7c, 0xba, 0x83 ); DEFINE_GUID( GUID_DEVCLASS_BATTERY, 0x72631e54L, 0x78a4, 0x11d0, 0xbc, 0xf7, 0x00, 0xaa, 0x00, 0xb7, 0xb3, 0x2a ); DEFINE_GUID( GUID_DEVCLASS_CDROM, 0x4d36e965L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_COMPUTER, 0x4d36e966L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_DECODER, 0x6bdd1fc2L, 0x810f, 0x11d0, 0xbe, 0xc7, 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f ); DEFINE_GUID( GUID_DEVCLASS_DISKDRIVE, 0x4d36e967L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_DISPLAY, 0x4d36e968L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_DOT4, 0x48721b56L, 0x6795, 0x11d2, 0xb1, 0xa8, 0x00, 0x80, 0xc7, 0x2e, 0x74, 0xa2 ); DEFINE_GUID( GUID_DEVCLASS_DOT4PRINT, 0x49ce6ac8L, 0x6f86, 0x11d2, 0xb1, 0xe5, 0x00, 0x80, 0xc7, 0x2e, 0x74, 0xa2 ); DEFINE_GUID( GUID_DEVCLASS_ENUM1394, 0xc459df55L, 0xdb08, 0x11d1, 0xb0, 0x09, 0x00, 0xa0, 0xc9, 0x08, 0x1f, 0xf6 ); DEFINE_GUID( GUID_DEVCLASS_FDC, 0x4d36e969L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_FLOPPYDISK, 0x4d36e980L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_GPS, 0x6bdd1fc3L, 0x810f, 0x11d0, 0xbe, 0xc7, 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f ); DEFINE_GUID( GUID_DEVCLASS_HDC, 0x4d36e96aL, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_HIDCLASS, 0x745a17a0L, 0x74d3, 0x11d0, 0xb6, 0xfe, 0x00, 0xa0, 0xc9, 0x0f, 0x57, 0xda ); DEFINE_GUID( GUID_DEVCLASS_IMAGE, 0x6bdd1fc6L, 0x810f, 0x11d0, 0xbe, 0xc7, 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f ); DEFINE_GUID( GUID_DEVCLASS_INFRARED, 0x6bdd1fc5L, 0x810f, 0x11d0, 0xbe, 0xc7, 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f ); DEFINE_GUID( GUID_DEVCLASS_BLUETOOTH, 0xe0cbf06cL, 0xcd8b, 0x4647, 0xbb, 0x8a, 0x26, 0x3b, 0x43, 0xf0, 0xf9, 0x74 ); DEFINE_GUID( GUID_DEVCLASS_KEYBOARD, 0x4d36e96bL, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_LEGACYDRIVER, 0x8ecc055dL, 0x047f, 0x11d1, 0xa5, 0x37, 0x00, 0x00, 0xf8, 0x75, 0x3e, 0xd1 ); DEFINE_GUID( GUID_DEVCLASS_MEDIA, 0x4d36e96cL, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_MEDIUM_CHANGER, 0xce5939aeL, 0xebde, 0x11d0, 0xb1, 0x81, 0x00, 0x00, 0xf8, 0x75, 0x3e, 0xc4 ); DEFINE_GUID( GUID_DEVCLASS_MODEM, 0x4d36e96dL, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_MONITOR, 0x4d36e96eL, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_MOUSE, 0x4d36e96fL, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_MTD, 0x4d36e970L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_MULTIFUNCTION, 0x4d36e971L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_MULTIPORTSERIAL, 0x50906cb8L, 0xba12, 0x11d1, 0xbf, 0x5d, 0x00, 0x00, 0xf8, 0x05, 0xf5, 0x30 ); DEFINE_GUID( GUID_DEVCLASS_NET, 0x4d36e972L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_NETCLIENT, 0x4d36e973L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_NETSERVICE, 0x4d36e974L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_NETTRANS, 0x4d36e975L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_NODRIVER, 0x4d36e976L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_PCMCIA, 0x4d36e977L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_PNPPRINTERS, 0x4658ee7eL, 0xf050, 0x11d1, 0xb6, 0xbd, 0x00, 0xc0, 0x4f, 0xa3, 0x72, 0xa7 ); DEFINE_GUID( GUID_DEVCLASS_PORTS, 0x4d36e978L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_PRINTER, 0x4d36e979L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_PRINTERUPGRADE, 0x4d36e97aL, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_PROCESSOR, 0x50127dc3L, 0x0f36, 0x415e, 0xa6, 0xcc, 0x4c, 0xb3, 0xbe, 0x91, 0x0B, 0x65 ); DEFINE_GUID( GUID_DEVCLASS_SBP2, 0xd48179beL, 0xec20, 0x11d1, 0xb6, 0xb8, 0x00, 0xc0, 0x4f, 0xa3, 0x72, 0xa7 ); DEFINE_GUID( GUID_DEVCLASS_SCSIADAPTER, 0x4d36e97bL, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_SMARTCARDREADER, 0x50dd5230L, 0xba8a, 0x11d1, 0xbf, 0x5d, 0x00, 0x00, 0xf8, 0x05, 0xf5, 0x30 ); DEFINE_GUID( GUID_DEVCLASS_SOUND, 0x4d36e97cL, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_SYSTEM, 0x4d36e97dL, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_TAPEDRIVE, 0x6d807884L, 0x7d21, 0x11cf, 0x80, 0x1c, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_UNKNOWN, 0x4d36e97eL, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 ); DEFINE_GUID( GUID_DEVCLASS_USB, 0x36fc9e60L, 0xc465, 0x11cf, 0x80, 0x56, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 ); DEFINE_GUID( GUID_DEVCLASS_VOLUME, 0x71a27cddL, 0x812a, 0x11d0, 0xbe, 0xc7, 0x08, 0x00, 0x2b, 0xe2, 0x09, 0x2f ); DEFINE_GUID( GUID_DEVCLASS_VOLUMESNAPSHOT, 0x533c5b84L, 0xec70, 0x11d2, 0x95, 0x05, 0x00, 0xc0, 0x4f, 0x79, 0xde, 0xaf ); DEFINE_GUID( GUID_DEVCLASS_WCEUSBS, 0x25dbce51L, 0x6c8f, 0x4a72, 0x8a, 0x6d, 0xb5, 0x4c, 0x2b, 0x4f, 0xc8, 0x35 );
// // Define filesystem filter classes used for classification and load ordering. // Classes are listed below in order from "highest" (i.e., farthest from the // filesystem) to "lowest" (i.e., closest to the filesystem). // DEFINE_GUID( GUID_DEVCLASS_FSFILTER_ACTIVITYMONITOR, 0xb86dff51L, 0xa31e, 0x4bac, 0xb3, 0xcf, 0xe8, 0xcf, 0xe7, 0x5c, 0x9f, 0xc2 ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_UNDELETE, 0xfe8f1572L, 0xc67a, 0x48c0, 0xbb, 0xac, 0x0b, 0x5c, 0x6d, 0x66, 0xca, 0xfb ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_ANTIVIRUS, 0xb1d1a169L, 0xc54f, 0x4379, 0x81, 0xdb, 0xbe, 0xe7, 0xd8, 0x8d, 0x74, 0x54 ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_REPLICATION, 0x48d3ebc4L, 0x4cf8, 0x48ff, 0xb8, 0x69, 0x9c, 0x68, 0xad, 0x42, 0xeb, 0x9f ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_CONTINUOUSBACKUP, 0x71aa14f8L, 0x6fad, 0x4622, 0xad, 0x77, 0x92, 0xbb, 0x9d, 0x7e, 0x69, 0x47 ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_CONTENTSCREENER, 0x3e3f0674L, 0xc83c, 0x4558, 0xbb, 0x26, 0x98, 0x20, 0xe1, 0xeb, 0xa5, 0xc5 ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_QUOTAMANAGEMENT, 0x8503c911L, 0xa6c7, 0x4919, 0x8f, 0x79, 0x50, 0x28, 0xf5, 0x86, 0x6b, 0x0c ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_SYSTEMRECOVERY, 0x2db15374L, 0x706e, 0x4131, 0xa0, 0xc7, 0xd7, 0xc7, 0x8e, 0xb0, 0x28, 0x9a ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_CFSMETADATASERVER, 0xcdcf0939L, 0xb75b, 0x4630, 0xbf, 0x76, 0x80, 0xf7, 0xba, 0x65, 0x58, 0x84 ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_HSM, 0xd546500aL, 0x2aeb, 0x45f6, 0x94, 0x82, 0xf4, 0xb1, 0x79, 0x9c, 0x31, 0x77 ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_COMPRESSION, 0xf3586bafL, 0xb5aa, 0x49b5, 0x8d, 0x6c, 0x05, 0x69, 0x28, 0x4c, 0x63, 0x9f ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_ENCRYPTION, 0xa0a701c0L, 0xa511, 0x42ff, 0xaa, 0x6c, 0x06, 0xdc, 0x03, 0x95, 0x57, 0x6f ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_PHYSICALQUOTAMANAGEMENT, 0x6a0a8e78L, 0xbba6, 0x4fc4, 0xa7, 0x09, 0x1e, 0x33, 0xcd, 0x09, 0xd6, 0x7e ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_OPENFILEBACKUP, 0xf8ecafa6L, 0x66d1, 0x41a5, 0x89, 0x9b, 0x66, 0x58, 0x5d, 0x72, 0x16, 0xb7 ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_SECURITYENHANCER, 0xd02bc3daL, 0x0c8e, 0x4945, 0x9b, 0xd5, 0xf1, 0x88, 0x3c, 0x22, 0x6c, 0x8c ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_COPYPROTECTION, 0x89786ff1L, 0x9c12, 0x402f, 0x9c, 0x9e, 0x17, 0x75, 0x3c, 0x7f, 0x43, 0x75 ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_SYSTEM, 0x5d1b9aaaL, 0x01e2, 0x46af, 0x84, 0x9f, 0x27, 0x2b, 0x3f, 0x32, 0x4c, 0x46 ); DEFINE_GUID( GUID_DEVCLASS_FSFILTER_INFRASTRUCTURE, 0xe55fa6f9L, 0x128c, 0x4d04, 0xab, 0xab, 0x63, 0x0c, 0x74, 0xb1, 0x45, 0x3a );
|