Программа для определения конфигурации компьютера и подключенных к нему устройств

Автор работы: Пользователь скрыл имя, 23 Мая 2013 в 22:22, курсовая работа

Описание работы

На сегодняшний день появилось огромное количество аппаратных средств персональных компьютеров различных производителей, которые выполняют самые разные задачи: ввод информации, выполнение кода программ, вывод результатов работы и т.д. Порой становится важной возможность определения конфигурации при не имении на руках документации на установленное оборудование и без разборки системного блока. В этом случае приходят на помощь программы специально разработанные для решения подобного рода задач – программы определения конфигурации компьютера.

Содержание работы

1. Введение 3
2. Основные теоретические сведения 4
3. Описание работы программы 7
4. Заключение 8
5. Список использованной литературы 9
Приложение. Листинг 10

Файлы: 1 файл

Записка_Кучик.docx

— 270.46 Кб (Скачать файл)

Петцольд Ч. Программирование для  Windows 95 BHV – Санкт-Питербург.

 

Приложение. Листинг

int GetDevices()

{

 

       HDEVINFO hDevInfo;

       SP_DEVINFO_DATA DeviceInfoData;

       DWORD i;

 

       // Create a HDEVINFO with all present devices.

       hDevInfo = SetupDiGetClassDevs(NULL,

           0, // Enumerator

           0,

           DIGCF_PRESENT | DIGCF_ALLCLASSES );

      

       if (hDevInfo == INVALID_HANDLE_VALUE)

       {

           // Insert error handling here.

           return 1;

       }

      

       // Enumerate through all devices in Set.

      

       DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);

       for (i=0;SetupDiEnumDeviceInfo(hDevInfo,i,

           &DeviceInfoData);i++)

       {

           DWORD DataT;

           LPTSTR buffer = NULL;

           DWORD buffersize = 0;

          

           //

           // Call function with null to begin with,

           // then use the returned buffer size (doubled)

           // to Alloc the buffer. Keep calling until

           // success or an unknown failure.

           //

           //  Double the returned buffersize to correct

           //  for underlying legacy CM functions that

           //  return an incorrect buffersize value on

           //  DBCS/MBCS systems.

           //

           while (!SetupDiGetDeviceRegistryProperty(

               hDevInfo,

               &DeviceInfoData,

               SPDRP_DEVICEDESC,

               &DataT,

               (PBYTE)buffer,

               buffersize,

               &buffersize))

           {

               if (GetLastError() ==

                   ERROR_INSUFFICIENT_BUFFER)

               {

                   // Change the buffer size.

                   if (buffer) LocalFree(buffer);

                   // Double the size to avoid problems on

                   // W2k MBCS systems per KB 888609.

                   buffer = (LPTSTR)LocalAlloc(LPTR,buffersize * 2);

               }

               else

               {

                   // Insert error handling here.

                   break;

               }

           }

          

  

   listBox1->Items->Add(gcnew String(buffer));

   //richTextBox1->Text += "\r\n";

   //_tprintf( TEXT("Result[%s]\n"), buffer );

           //printf("Result:[%s]\n",buffer);

   //cout<<buffer;

          

           if (buffer) LocalFree(buffer);

       }

      

      

       if ( GetLastError()!=NO_ERROR &&

            GetLastError()!=ERROR_NO_MORE_ITEMS )

       {

           // Insert error handling here.

           return 1;

       }

      

       //  Cleanup

       SetupDiDestroyDeviceInfoList(hDevInfo);

 

   getch();

      

       return 0;

}

 


 

int GetDeviceInfo(int index)

{

richTextBox2->Clear();

HDEVINFO hDevInfo;

    SP_DEVINFO_DATA DeviceInfoData;

    DWORD i;

 

        // Create a HDEVINFO with all present devices.

    hDevInfo = SetupDiGetClassDevs(NULL,

   0, // Enumerator

   0,

   DIGCF_PRESENT | DIGCF_ALLCLASSES );

      

    if (hDevInfo == INVALID_HANDLE_VALUE)

    {

    // Insert error handling here.

    return 1;

    }

      

    // Enumerate through all devices in Set.

      

    DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);

 

SetupDiEnumDeviceInfo(hDevInfo, index, &DeviceInfoData);

 

DWORD DataT;

            LPTSTR buffer = NULL;

            DWORD buffersize = 0;

 

/// <summary>

/// DeviceDesc (R/W)

/// </summary>

while (!SetupDiGetDeviceRegistryProperty(

               hDevInfo,

               &DeviceInfoData,

               SPDRP_DEVICEDESC,

               &DataT,

               (PBYTE)buffer,

               buffersize,

               &buffersize))

           {

               if (GetLastError() ==

                   ERROR_INSUFFICIENT_BUFFER)

               {

                   // Change the buffer size.

                   if (buffer) LocalFree(buffer);

                   // Double the size to avoid problems on

                   // W2k MBCS systems per KB 888609.

                   buffer = (LPTSTR)LocalAlloc(LPTR,buffersize * 2);

               }

               else

               {

                   // Insert error handling here.

                   break;

               }

           }

 

richTextBox2->Text += "DeviceDesc: \r\n";

richTextBox2->Text += gcnew String(buffer);

richTextBox2->Text += "\r\n------------------\r\n";

 

if (buffer) LocalFree(buffer);

 

            buffer = NULL;

            buffersize = 0;

 

/// <summary>

/// HardwareID (R/W)

/// </summary>

while (!SetupDiGetDeviceRegistryProperty(

               hDevInfo,

               &DeviceInfoData,

               SPDRP_HARDWAREID ,

               &DataT,

               (PBYTE)buffer,

               buffersize,

               &buffersize))

           {

               if (GetLastError() ==

                   ERROR_INSUFFICIENT_BUFFER)

               {

                   // Change the buffer size.

                   if (buffer) LocalFree(buffer);

                   // Double the size to avoid problems on

                   // W2k MBCS systems per KB 888609.

                   buffer = (LPTSTR)LocalAlloc(LPTR,buffersize * 2);

               }

               else

               {

                   // Insert error handling here.

                   break;

               }

           }

 

richTextBox2->Text += "HardwareID: \r\n";

richTextBox2->Text += gcnew String(buffer);

richTextBox2->Text += "\r\n------------------\r\n";

 

if (buffer) LocalFree(buffer); 

 

buffer = NULL;

            buffersize = 0;

 

/// <summary>

/// Service (R/W)

/// </summary>

while (!SetupDiGetDeviceRegistryProperty(

               hDevInfo,

               &DeviceInfoData,

               SPDRP_SERVICE ,

               &DataT,

               (PBYTE)buffer,

               buffersize,

               &buffersize))

           {

               if (GetLastError() ==

                   ERROR_INSUFFICIENT_BUFFER)

               {

                   // Change the buffer size.

                   if (buffer) LocalFree(buffer);

                   // Double the size to avoid problems on

                   // W2k MBCS systems per KB 888609.

                   buffer = (LPTSTR)LocalAlloc(LPTR,buffersize * 2);

               }

               else

               {

                   // Insert error handling here.

                   break;

               }

           }

 

richTextBox2->Text += "Service: \r\n";

richTextBox2->Text += gcnew String(buffer);

richTextBox2->Text += "\r\n------------------\r\n";

 

if (buffer) LocalFree(buffer);

 

buffer = NULL;

            buffersize = 0;

 

/// <summary>

/// Class (R--tied to ClassGUID)

/// </summary>

while (!SetupDiGetDeviceRegistryProperty(

               hDevInfo,

               &DeviceInfoData,

               SPDRP_CLASS ,

               &DataT,

               (PBYTE)buffer,

               buffersize,

               &buffersize))

           {

               if (GetLastError() ==

                   ERROR_INSUFFICIENT_BUFFER)

               {

                   // Change the buffer size.

                   if (buffer) LocalFree(buffer);

                   // Double the size to avoid problems on

                   // W2k MBCS systems per KB 888609.

                   buffer = (LPTSTR)LocalAlloc(LPTR,buffersize * 2);

               }

               else

               {

                   // Insert error handling here.

                   break;

               }

           }

 

richTextBox2->Text += "Class: \r\n";

richTextBox2->Text += gcnew String(buffer);

richTextBox2->Text += "\r\n------------------\r\n";

 

if (buffer) LocalFree(buffer);

 

buffer = NULL;

            buffersize = 0;

 

while (!SetupDiGetDeviceRegistryProperty(

               hDevInfo,

               &DeviceInfoData,

               SPDRP_DRIVER ,

               &DataT,

               (PBYTE)buffer,

               buffersize,

               &buffersize))

           {

               if (GetLastError() ==

                   ERROR_INSUFFICIENT_BUFFER)

               {

                   // Change the buffer size.

                   if (buffer) LocalFree(buffer);

                   // Double the size to avoid problems on

                   // W2k MBCS systems per KB 888609.

                   buffer = (LPTSTR)LocalAlloc(LPTR,buffersize * 2);

               }

               else

               {

                   // Insert error handling here.

                   break;

               }

           }

 

richTextBox2->Text += "Driver: \r\n";

richTextBox2->Text += gcnew String(buffer);

richTextBox2->Text += "\r\n------------------\r\n";

 

if (buffer) LocalFree(buffer);

 

buffer = NULL;

            buffersize = 0;

 

/// <summary>

/// FriendlyName (R/W)

/// </summary>

while (!SetupDiGetDeviceRegistryProperty(

               hDevInfo,

               &DeviceInfoData,

               SPDRP_FRIENDLYNAME ,

               &DataT,

               (PBYTE)buffer,

               buffersize,

               &buffersize))

           {

               if (GetLastError() ==

                   ERROR_INSUFFICIENT_BUFFER)

               {

                   // Change the buffer size.

                   if (buffer) LocalFree(buffer);

                   // Double the size to avoid problems on

                   // W2k MBCS systems per KB 888609.

                   buffer = (LPTSTR)LocalAlloc(LPTR,buffersize * 2);

               }

               else

               {

                   // Insert error handling here.

                   break;

               }

           }

 

richTextBox2->Text += "FriendlyName: \r\n";

richTextBox2->Text += gcnew String(buffer);

richTextBox2->Text += "\r\n------------------\r\n";

 

if (buffer) LocalFree(buffer);

 

buffer = NULL;

            buffersize = 0;

 

/// <summary>

/// LocationInformation (R/W)

/// </summary>

while (!SetupDiGetDeviceRegistryProperty(

               hDevInfo,

               &DeviceInfoData,

               SPDRP_LOCATION_INFORMATION ,

               &DataT,

               (PBYTE)buffer,

               buffersize,

               &buffersize))

           {

               if (GetLastError() ==

                   ERROR_INSUFFICIENT_BUFFER)

               {

                   // Change the buffer size.

                   if (buffer) LocalFree(buffer);

                   // Double the size to avoid problems on

                   // W2k MBCS systems per KB 888609.

                   buffer = (LPTSTR)LocalAlloc(LPTR,buffersize * 2);

               }

               else

               {

                   // Insert error handling here.

                   break;

               }

           }

 

richTextBox2->Text += "LocationInformation: \r\n";

richTextBox2->Text += gcnew String(buffer);

richTextBox2->Text += "\r\n------------------\r\n";

 

if (buffer) LocalFree(buffer);

 

buffer = NULL;

            buffersize = 0;

 

/// <summary>

/// PhysicalDeviceObjectName (R)

/// </summary>

while (!SetupDiGetDeviceRegistryProperty(

               hDevInfo,

               &DeviceInfoData,

               SPDRP_PHYSICAL_DEVICE_OBJECT_NAME,

               &DataT,

               (PBYTE)buffer,

               buffersize,

               &buffersize))

           {

               if (GetLastError() ==

                   ERROR_INSUFFICIENT_BUFFER)

               {

                   // Change the buffer size.

                   if (buffer) LocalFree(buffer);

                   // Double the size to avoid problems on

                   // W2k MBCS systems per KB 888609.

                   buffer = (LPTSTR)LocalAlloc(LPTR,buffersize * 2);

               }

               else

               {

                   // Insert error handling here.

                   break;

               }

           }

 

richTextBox2->Text += "PhysicalDeviceObjectName: \r\n";

richTextBox2->Text += gcnew String(buffer);

richTextBox2->Text += "\r\n------------------\r\n";

 

if (buffer) LocalFree(buffer);

 

buffer = NULL;

            buffersize = 0;

 

/// <summary>

/// Enumerator Name (R)

/// </summary>

while (!SetupDiGetDeviceRegistryProperty(

               hDevInfo,

               &DeviceInfoData,

               SPDRP_ENUMERATOR_NAME ,

               &DataT,

               (PBYTE)buffer,

               buffersize,

               &buffersize))

           {

               if (GetLastError() ==

                   ERROR_INSUFFICIENT_BUFFER)

               {

                   // Change the buffer size.

                   if (buffer) LocalFree(buffer);

                   // Double the size to avoid problems on

                   // W2k MBCS systems per KB 888609.

                   buffer = (LPTSTR)LocalAlloc(LPTR,buffersize * 2);

               }

               else

               {

                   // Insert error handling here.

                   break;

               }

           }

 

richTextBox2->Text += "Enumerator Name: \r\n";

richTextBox2->Text += gcnew String(buffer);

richTextBox2->Text += "\r\n------------------\r\n";

 

if (buffer) LocalFree(buffer);   

 

}

 


Информация о работе Программа для определения конфигурации компьютера и подключенных к нему устройств