<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=351895&amp;view=findpost&amp;p=3084911</guid>
        <pubDate>Sun, 26 Feb 2012 13:14:56 +0000</pubDate>
        <title>Получить инфо о серийном номере, производителе и названии USB Storage Device</title>
        <link>https://forum.sources.ru/index.php?showtopic=351895&amp;view=findpost&amp;p=3084911</link>
        <description><![CDATA[neokoder: <strong class='tag-b'>Получить инфо о серийном номере, производителе и названии USB Storage Device.</strong><br>
Если тестируемый диск является съёмным диском USB Storage Device(флешка, телефон, mp3-плеер и т.д.) функция PrintFlashDriveInfo печатает название производителя устройства, название продукта и серийный номер устройства. Если диск не является USB Storage Device, то выводится об этом сообщение. Функция работает с полным контролем ошибок.<br>
<br>
При необходимости получения выходных параметров(серийный номер, вендор, название) в качестве переменных вместо печати, функция легко переделывается:  можно ввести дополнительный выходной параметр-структуру из 3-х строк и их размеров и заполнять её вместо печати.<br>
<br>
<em class='tag-i'>Примечание: при получении инфо о USB-устройстве таким способом, иногда внешний жесткий диск также может определиться как съёмное USB-устройство. В этом случае можно ввести доп. проверку того <a class='tag-url' href='http://forum.sources.ru/index.php?showtopic=351430' target='_blank'>является ли диск съёмным USB Storage Device</a> (1 Способ по ссылке)</em><br>
<br>
<br>
<strong class='tag-b'>PrintFlashDriveInfo</strong><br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">WCHAR* GetElem(WCHAR *ptr,WCHAR delim,WCHAR *buf)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; WCHAR *ptr1=NULL;</div><div class="code_line">&nbsp;&nbsp; ptr1=wcschr(ptr,delim);</div><div class="code_line">&nbsp;&nbsp; if (ptr1)</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;wcsncpy(buf,ptr,(int)(ptr1-ptr));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;buf[(int)(ptr1-ptr)]=0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;return (ptr1+1);</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">&nbsp;&nbsp; else</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;wcscpy(buf,ptr);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;return NULL;</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">}</div><div class="code_line">&nbsp;</div><div class="code_line">//Входные данные:</div><div class="code_line">// drive_letter - буква диска</div><div class="code_line">void PrintFlashDriveInfo(WCHAR drive_letter)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; HKEY hk=NULL;</div><div class="code_line">&nbsp;&nbsp; LONG Ret=0;</div><div class="code_line">&nbsp;&nbsp; HANDLE hdrive=INVALID_HANDLE_VALUE;</div><div class="code_line">&nbsp;&nbsp; DWORD data_size,dtype;</div><div class="code_line">&nbsp;&nbsp; WCHAR *data=NULL,*buf1=NULL,*buf2=NULL;</div><div class="code_line">&nbsp;&nbsp; WCHAR *ptr1_1=NULL,*ptr1_2=NULL,*ptr2_1=NULL,*ptr2_2=NULL;</div><div class="code_line">&nbsp;&nbsp; WCHAR dos_link[50];</div><div class="code_line">&nbsp;&nbsp; WCHAR drive_name2[20];</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; __try</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;//проверяем существует ли диск в системе</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;wsprintf(drive_name2,L&quot;\\.\%c:&quot;,drive_letter);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;hdrive = CreateFileW(drive_name2,0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (hdrive==INVALID_HANDLE_VALUE)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; wprintf(L&quot;Ошибка PrintFlashDriveInfo: Ошибка CreateFile: %u\n\n&quot;,GetLastError());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; __leave;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;CloseHandle(hdrive);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE,L&quot;SYSTEM\MountedDevices&quot;,0,KEY_READ,&amp;hk);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (Ret!=ERROR_SUCCESS)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; wprintf(L&quot;Ошибка PrintFlashDriveInfo: Ошибка RegOpenKeyEx: %u\n\n&quot;,Ret);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; __leave;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;wsprintf(dos_link,L&quot;\DosDevices\%c:&quot;,drive_letter);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Ret=RegQueryValueExW(hk,dos_link,NULL,&amp;dtype,NULL,&amp;data_size);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (Ret==ERROR_SUCCESS)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; data=(WCHAR *)malloc(data_size+2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; buf1=(WCHAR *)malloc(data_size+2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; buf2=(WCHAR *)malloc(data_size+2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if (data==NULL||buf1==NULL||buf2==NULL)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wprintf(L&quot;Ошибка PrintFlashDriveInfo: Ошибка malloc.\n\n&quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;__leave;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; memset(data,0,data_size+2);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; Ret=RegQueryValueExW(hk,dos_link,NULL,&amp;dtype,(LPBYTE)data,&amp;data_size);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if (Ret!=ERROR_SUCCESS)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wprintf(L&quot;Ошибка PrintFlashDriveInfo: Ошибка RegQueryValueEx: %u\n\n&quot;,Ret);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;__leave;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if(wcsstr(data,L&quot;USBSTOR&quot;)!=NULL)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wprintf(L&quot;Данные флеш-диска %c:\n&quot;,drive_letter);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ptr1_1=GetElem(data,L&#39;#&#39;,buf1);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (ptr1_1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ptr1_2=GetElem(ptr1_1,L&#39;#&#39;,buf1);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ptr1_1=buf1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ptr2_2=GetElem(ptr1_1,L&#39;&amp;&#39;,buf2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (wcsstr(buf2,L&quot;Ven_&quot;))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wprintf(L&quot;Производитель: %s\n&quot;,buf2+4);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else if (wcsstr(buf2,L&quot;Prod_&quot;))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wprintf(L&quot;Название продукта: %s\n&quot;,buf2+5);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ptr1_1=ptr2_2;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } while (ptr2_2);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ptr1_1=GetElem(ptr1_2,L&#39;#&#39;,buf1);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ptr1_1=buf1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ptr2_2=GetElem(ptr1_1,L&#39;&amp;&#39;,buf2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (wcslen(buf2)&#62;3)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wprintf(L&quot;Серийный номер: %s\n&quot;,buf2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ptr1_1=ptr2_2;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } while (ptr2_2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }//if USBSTOR</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wprintf(L&quot;Диск %c: НЕ является флешкой\n&quot;,drive_letter);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; wprintf(L&quot;Ошибка PrintFlashDriveInfo: Ошибка RegQueryValueEx: %u\n&quot;,Ret);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;wprintf(L&quot;\n&quot;);</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">&nbsp;&nbsp; __finally</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (data!=NULL) free(data);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (buf1!=NULL) free(buf1);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (buf2!=NULL) free(buf2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (hk!=NULL) RegCloseKey(hk);</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">}</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
<br>
<strong class='tag-b'>Использование</strong><br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&nbsp;&nbsp; PrintFlashDriveInfo(_T(&#39;G&#39;));</div><div class="code_line">&nbsp;&nbsp; PrintFlashDriveInfo(_T(&#39;C&#39;));</div><div class="code_line">&nbsp;&nbsp; PrintFlashDriveInfo(_T(&#39;H&#39;));</div><div class="code_line">&nbsp;&nbsp; PrintFlashDriveInfo(_T(&#39;I&#39;));</div></ol></div></div></div></div><br>
<br>
<br>
<strong class='tag-b'>Полный исходный код</strong><br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">#define UNICODE</div><div class="code_line">#define _UNICODE</div><div class="code_line">#include &#60;windows.h&#62;</div><div class="code_line">#include &#60;stdio.h&#62;</div><div class="code_line">#include &#60;conio.h&#62;</div><div class="code_line">#include &#60;locale.h&#62;</div><div class="code_line">#include &#60;WinIoCtl.h&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">WCHAR* GetElem(WCHAR *ptr,WCHAR delim,WCHAR *buf)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; WCHAR *ptr1=NULL;</div><div class="code_line">&nbsp;&nbsp; ptr1=wcschr(ptr,delim);</div><div class="code_line">&nbsp;&nbsp; if (ptr1)</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;wcsncpy(buf,ptr,(int)(ptr1-ptr));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;buf[(int)(ptr1-ptr)]=0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;return (ptr1+1);</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">&nbsp;&nbsp; else</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;wcscpy(buf,ptr);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;return NULL;</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">}</div><div class="code_line">&nbsp;</div><div class="code_line">//Входные данные:</div><div class="code_line">// drive_letter - буква диска</div><div class="code_line">void PrintFlashDriveInfo(WCHAR drive_letter)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; HKEY hk=NULL;</div><div class="code_line">&nbsp;&nbsp; LONG Ret=0;</div><div class="code_line">&nbsp;&nbsp; HANDLE hdrive=INVALID_HANDLE_VALUE;</div><div class="code_line">&nbsp;&nbsp; DWORD data_size,dtype;</div><div class="code_line">&nbsp;&nbsp; WCHAR *data=NULL,*buf1=NULL,*buf2=NULL;</div><div class="code_line">&nbsp;&nbsp; WCHAR *ptr1_1=NULL,*ptr1_2=NULL,*ptr2_1=NULL,*ptr2_2=NULL;</div><div class="code_line">&nbsp;&nbsp; WCHAR dos_link[50];</div><div class="code_line">&nbsp;&nbsp; WCHAR drive_name2[20];</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; __try</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;//проверяем существует ли диск в системе</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;wsprintf(drive_name2,L&quot;\\.\%c:&quot;,drive_letter);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;hdrive = CreateFileW(drive_name2,0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (hdrive==INVALID_HANDLE_VALUE)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; wprintf(L&quot;Ошибка PrintFlashDriveInfo: Ошибка CreateFile: %u\n\n&quot;,GetLastError());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; __leave;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;CloseHandle(hdrive);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE,L&quot;SYSTEM\MountedDevices&quot;,0,KEY_READ,&amp;hk);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (Ret!=ERROR_SUCCESS)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; wprintf(L&quot;Ошибка PrintFlashDriveInfo: Ошибка RegOpenKeyEx: %u\n\n&quot;,Ret);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; __leave;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;wsprintf(dos_link,L&quot;\DosDevices\%c:&quot;,drive_letter);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Ret=RegQueryValueExW(hk,dos_link,NULL,&amp;dtype,NULL,&amp;data_size);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (Ret==ERROR_SUCCESS)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; data=(WCHAR *)malloc(data_size+2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; buf1=(WCHAR *)malloc(data_size+2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; buf2=(WCHAR *)malloc(data_size+2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if (data==NULL||buf1==NULL||buf2==NULL)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wprintf(L&quot;Ошибка PrintFlashDriveInfo: Ошибка malloc.\n\n&quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;__leave;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; memset(data,0,data_size+2);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; Ret=RegQueryValueExW(hk,dos_link,NULL,&amp;dtype,(LPBYTE)data,&amp;data_size);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if (Ret!=ERROR_SUCCESS)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wprintf(L&quot;Ошибка PrintFlashDriveInfo: Ошибка RegQueryValueEx: %u\n\n&quot;,Ret);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;__leave;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if(wcsstr(data,L&quot;USBSTOR&quot;)!=NULL)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wprintf(L&quot;Данные флеш-диска %c:\n&quot;,drive_letter);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ptr1_1=GetElem(data,L&#39;#&#39;,buf1);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (ptr1_1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ptr1_2=GetElem(ptr1_1,L&#39;#&#39;,buf1);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ptr1_1=buf1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ptr2_2=GetElem(ptr1_1,L&#39;&amp;&#39;,buf2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (wcsstr(buf2,L&quot;Ven_&quot;))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wprintf(L&quot;Производитель: %s\n&quot;,buf2+4);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else if (wcsstr(buf2,L&quot;Prod_&quot;))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wprintf(L&quot;Название продукта: %s\n&quot;,buf2+5);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ptr1_1=ptr2_2;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } while (ptr2_2);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ptr1_1=GetElem(ptr1_2,L&#39;#&#39;,buf1);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ptr1_1=buf1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ptr2_2=GetElem(ptr1_1,L&#39;&amp;&#39;,buf2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (wcslen(buf2)&#62;3)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wprintf(L&quot;Серийный номер: %s\n&quot;,buf2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ptr1_1=ptr2_2;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } while (ptr2_2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }//if USBSTOR</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;wprintf(L&quot;Диск %c: НЕ является флешкой\n&quot;,drive_letter);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; wprintf(L&quot;Ошибка PrintFlashDriveInfo: Ошибка RegQueryValueEx: %u\n&quot;,Ret);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;wprintf(L&quot;\n&quot;);</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">&nbsp;&nbsp; __finally</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (data!=NULL) free(data);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (buf1!=NULL) free(buf1);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (buf2!=NULL) free(buf2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (hk!=NULL) RegCloseKey(hk);</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">int wmain(int argc, WCHAR* argv[])</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; setlocale(LC_ALL,&quot;Russian&quot;);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; PrintFlashDriveInfo(L&#39;H&#39;);</div><div class="code_line">&nbsp;&nbsp; PrintFlashDriveInfo(L&#39;G&#39;);</div><div class="code_line">&nbsp;&nbsp; PrintFlashDriveInfo(L&#39;C&#39;);</div><div class="code_line">&nbsp;&nbsp; PrintFlashDriveInfo(L&#39;Я&#39;);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; wprintf(L&quot;Нажмите любую клавишу...&quot;);</div><div class="code_line">&nbsp;&nbsp; _getch();</div><div class="code_line">&nbsp;&nbsp; return 0;</div><div class="code_line">}</div></ol></div></div></div></div><br>
<br>
p.s. учитывая &quot;просьбы&quot; :) код передалан из универсального(работающего как с UNICODE так и с обычной 8-ми битовой ANSI-строкой) в код работающий только с UNICODE.]]></description>
        <author>neokoder</author>
        <category>C/C++ FAQ</category>
      </item>
	
      </channel>
      </rss>
	