<?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=351422&amp;view=findpost&amp;p=3080751</guid>
        <pubDate>Sun, 19 Feb 2012 17:26:31 +0000</pubDate>
        <title>Определить является ли диск съёмным USB Storage Device</title>
        <link>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080751</link>
        <description><![CDATA[neokoder: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=351422&view=findpost&p=3080747'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Мальчиш &#064; <time class="tag-quote__quoted-time" datetime="2012-02-19T17:15:46+00:00">19.02.12, 17:15</time></span><div class='quote '>в код невникал - какой-то он гнилой, я юзал вот это:</div></div><br>
Ты за базаром следи. <br>
<br>
<span class="tag-color tag-color-named" data-value="gray" style="color: gray"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2012-02-19T21:33:30+04:00">19.02.12, 17:33</time></span></span><br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=351422&view=findpost&p=3080747'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Мальчиш &#064; <time class="tag-quote__quoted-time" datetime="2012-02-19T17:15:46+00:00">19.02.12, 17:15</time></span><div class='quote '>я юзал вот это:</div></div><br>
3 раза ХА  :D . Это ты только по шине USB определял? Твой код во многих случаях работать не будет, в частности внешний жесткий диск сочтёт за флешку. И твой код не будет работать под бычным юзером в XP  :). Кроме того если на вход твоей функции подать несуществующую букву диска, то она вернёт не ошибку, как должно быть а сообщит, что диск не флешка&#33;  :D  :D <br>
<br>
В общем ты в следующий раз прежде чем чей-то код называть <em class='tag-i'>гнилым</em>, лучше повысь свой профессиональный навык, а то так умея только делать супер-пупер профессионально <a class='tag-url' href='http://forum.sources.ru/index.php?showtopic=351424&view=findpost&p=3080746' target='_blank'>парсинг строки</a> ты далеко не уедешь  :D &#33;<br>
<br>
Главное сам &quot;продемонстрировал&quot; 4-х кратно вложенный IF, а меня в параллельной теме упрекает за чрезмерную вложенность  :) .]]></description>
        <author>neokoder</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080747</guid>
        <pubDate>Sun, 19 Feb 2012 17:15:46 +0000</pubDate>
        <title>Определить является ли диск съёмным USB Storage Device</title>
        <link>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080747</link>
        <description><![CDATA[Мальчиш: в код невникал - какой-то он гнилой, я юзал вот это:<br>
<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 DRIVE_FIXED_USB 7</div><div class="code_line">&nbsp;</div><div class="code_line">BOOL GetDisksProperty(HANDLE hDevice, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;STORAGE_PROPERTY_QUERY &nbsp;Query; &nbsp;// input param for query</div><div class="code_line">&nbsp;&nbsp; &nbsp;DWORD dwOutBytes; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // IOCTL output length</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;// specify the query type</div><div class="code_line">&nbsp;&nbsp; &nbsp;Query.PropertyId = StorageDeviceProperty;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Query.QueryType = PropertyStandardQuery;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;// Query using IOCTL_STORAGE_QUERY_PROPERTY </div><div class="code_line">&nbsp;&nbsp; &nbsp;return DeviceIoControl(hDevice, &nbsp; &nbsp; &nbsp; &nbsp; // device handle</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;IOCTL_STORAGE_QUERY_PROPERTY, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // info of device property</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&amp;Query, sizeof(STORAGE_PROPERTY_QUERY), // input data buffer</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;pDevDesc, pDevDesc-&#62;Size, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // output data buffer</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&amp;dwOutBytes, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// out&#39;s length</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;(LPOVERLAPPED)NULL); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div class="code_line">}</div><div class="code_line">&nbsp;</div><div class="code_line">BOOL isItUsbDrive(const QString &amp; drive)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;bool bUsb = false;</div><div class="code_line">&nbsp;&nbsp; &nbsp;PSTORAGE_DEVICE_DESCRIPTOR pDevDesc;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;HANDLE hDevice = CreateFile(drive.utf16(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;if(hDevice != INVALID_HANDLE_VALUE)</div><div class="code_line">&nbsp;&nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;pDevDesc = (PSTORAGE_DEVICE_DESCRIPTOR)new BYTE[sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 - 1];</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(pDevDesc != NULL)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pDevDesc-&#62;Size = sizeof(STORAGE_DEVICE_DESCRIPTOR) + 512 -1;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(GetDisksProperty(hDevice, pDevDesc))</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; &nbsp;if(pDevDesc-&#62;BusType == BusTypeUsb)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bUsb = true;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delete [] pDevDesc;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;CloseHandle(hDevice);</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;return bUsb;</div><div class="code_line">}</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script>]]></description>
        <author>Мальчиш</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080694</guid>
        <pubDate>Sun, 19 Feb 2012 14:47:19 +0000</pubDate>
        <title>Определить является ли диск съёмным USB Storage Device</title>
        <link>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080694</link>
        <description><![CDATA[neokoder: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=351422&view=findpost&p=3080604'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>B.V. &#064; <time class="tag-quote__quoted-time" datetime="2012-02-19T10:52:51+00:00">19.02.12, 10:52</time></span><div class='quote '>Можно было бы придраться и к смешиванию юникода, макроса _T и ANSI, но это уже мелочи</div></div><br>
Вряд ли  8-) . <a class='tag-url' href='http://forum.sources.ru/index.php?showtopic=351424&view=findpost&p=3080693' target='_blank'>Здесь по-другому просто нельзя</a> поскольку строка из реестра WCHAR.]]></description>
        <author>neokoder</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080604</guid>
        <pubDate>Sun, 19 Feb 2012 10:52:51 +0000</pubDate>
        <title>Определить является ли диск съёмным USB Storage Device</title>
        <link>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080604</link>
        <description><![CDATA[B.V.: Можно было бы придраться и к смешиванию юникода, макроса _T и ANSI, но это уже мелочи<br>Пост ушел в FAQ]]></description>
        <author>B.V.</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080589</guid>
        <pubDate>Sun, 19 Feb 2012 09:26:44 +0000</pubDate>
        <title>Определить является ли диск съёмным USB Storage Device</title>
        <link>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080589</link>
        <description><![CDATA[neokoder: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=351422&view=findpost&p=3080579'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Dem_max &#064; <time class="tag-quote__quoted-time" datetime="2012-02-19T08:39:29+00:00">19.02.12, 08:39</time></span><div class='quote '>надо бы StringCchPrintf заменить на wsprintf ибо StringCchPrintf компиляторозависимое.</div></div><br>
wsprintf вообще-то уже давно не рекомендуется к использованию по соображениям безопасности.<br>
Кому надо пусть меняет. Мне больше нравится как StringCchPrintf обрабатывает ошибки. swprintf_s может организовать вылет из программы, если не использовать дополнительно _set_invalid_parameter_handler, вот эта <em class='tag-i'>дополнительность</em> меня лично и обременяет. <br>
<br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=351422&view=findpost&p=3080579'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Dem_max &#064; <time class="tag-quote__quoted-time" datetime="2012-02-19T08:39:29+00:00">19.02.12, 08:39</time></span><div class='quote '>да и использование malloc как то не кошерно, лучше через new</div></div><br>
Не вижу никаких причин для замены malloc на new.]]></description>
        <author>neokoder</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080579</guid>
        <pubDate>Sun, 19 Feb 2012 08:39:29 +0000</pubDate>
        <title>Определить является ли диск съёмным USB Storage Device</title>
        <link>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080579</link>
        <description><![CDATA[Dem_max: надо бы <strong class='tag-b'>StringCchPrintf</strong> заменить на <strong class='tag-b'>wsprintf</strong> ибо <strong class='tag-b'>StringCchPrintf</strong> компиляторозависимое.<br>
<br>
да и использование <strong class='tag-b'>malloc</strong> как то не кошерно, лучше через <strong class='tag-b'>new</strong>]]></description>
        <author>Dem_max</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080542</guid>
        <pubDate>Sun, 19 Feb 2012 06:01:32 +0000</pubDate>
        <title>Определить является ли диск съёмным USB Storage Device</title>
        <link>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080542</link>
        <description><![CDATA[neokoder: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=351422&view=findpost&p=3080539'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Бублик &#064; <time class="tag-quote__quoted-time" datetime="2012-02-19T05:55:43+00:00">19.02.12, 05:55</time></span><div class='quote '>Для FAQ тема подходит и...  по-моему, на 25 Dgm тянет&#33;&#33;&#33;</div></div><br>
Спасибо за высокую оценку <strong class='tag-b'>Бублик</strong> ;), но в правилах вроде прописано максимум 10 DigiMania за один FAQ. А вообще не ради DigiMania пишу, но повышение рейтинга это тож хорошо  :yes: &#33;]]></description>
        <author>neokoder</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080539</guid>
        <pubDate>Sun, 19 Feb 2012 05:55:43 +0000</pubDate>
        <title>Определить является ли диск съёмным USB Storage Device</title>
        <link>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080539</link>
        <description><![CDATA[Бублик: Для FAQ тема подходит и... ;) по-моему, на 25 Dgm тянет&#33;&#33;&#33;]]></description>
        <author>Бублик</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080538</guid>
        <pubDate>Sun, 19 Feb 2012 05:45:40 +0000</pubDate>
        <title>Определить является ли диск съёмным USB Storage Device</title>
        <link>https://forum.sources.ru/index.php?showtopic=351422&amp;view=findpost&amp;p=3080538</link>
        <description><![CDATA[neokoder: <strong class='tag-b'>Определить является ли диск съёмным USB Storage Device(флеш-диски, телефоны, подключенные как USB Storage, mp3-плееры и т.д.).</strong><br>
Код универсальный, может работать как с UNICODE, так и с обычной 8-ми битовой ANSI-строкой.<br>
<br>
<span class='tag-size' data-value='14' style='font-size:14pt;'>1 Способ</span><br>
Этот способ предпочтительней, так как второй может <span class='tag-u'>иногда</span> внешний жесткий диск также определить как съёмное USB-устройство.<br>
<br>
<strong class='tag-b'>IsFlashDrive</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">//Входные данные: </div><div class="code_line">// drive_letter - буква тетируемого диска</div><div class="code_line">//Коды возврата:</div><div class="code_line">//0 - диск не является флешкой</div><div class="code_line">//1 - диск является флешкой</div><div class="code_line">//2,3 - ошибки</div><div class="code_line">__int8 IsFlashDrive(TCHAR drive_letter)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; UINT drive_type;</div><div class="code_line">&nbsp;&nbsp; STORAGE_PROPERTY_QUERY spq;</div><div class="code_line">&nbsp;&nbsp; STORAGE_DEVICE_DESCRIPTOR sdd;</div><div class="code_line">&nbsp;&nbsp; DWORD BytesReturned;</div><div class="code_line">&nbsp;&nbsp; HANDLE hdrive=INVALID_HANDLE_VALUE;</div><div class="code_line">&nbsp;&nbsp; TCHAR drive_name1[20],drive_name2[20];</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; StringCchPrintf(drive_name1,20,_T(&quot;%c:\&quot;),drive_letter);</div><div class="code_line">&nbsp;&nbsp; StringCchPrintf(drive_name2,20,_T(&quot;\\.\%c:&quot;),drive_letter);</div><div class="code_line">&nbsp;&nbsp;</div><div class="code_line">&nbsp;&nbsp; drive_type=GetDriveType(drive_name1);</div><div class="code_line">&nbsp;&nbsp; </div><div class="code_line">&nbsp;&nbsp; hdrive = CreateFile(drive_name2,0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);</div><div class="code_line">&nbsp;&nbsp; if (hdrive==INVALID_HANDLE_VALUE)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;return 2;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; memset(&amp;spq,0,sizeof(spq));</div><div class="code_line">&nbsp;&nbsp; memset(&amp;sdd,0,sizeof(sdd));</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; spq.PropertyId=StorageDeviceProperty;</div><div class="code_line">&nbsp;&nbsp; spq.QueryType=PropertyStandardQuery;</div><div class="code_line">&nbsp;&nbsp; if (!DeviceIoControl(hdrive,IOCTL_STORAGE_QUERY_PROPERTY,&amp;spq,sizeof(spq),&amp;sdd,sizeof(sdd),&amp;BytesReturned,NULL))</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; CloseHandle(hdrive);</div><div class="code_line">&nbsp;&nbsp; &nbsp; return 3;</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; CloseHandle(hdrive);</div><div class="code_line">&nbsp;&nbsp; if ((drive_type==DRIVE_REMOVABLE)&amp;&amp;(sdd.BusType==BusTypeUsb)&amp;&amp;(sdd.RemovableMedia==true))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;return 1;</div><div class="code_line">&nbsp;&nbsp; else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;return 0;</div><div class="code_line">}</div></ol></div></div></div></div><br>
<br>
<strong class='tag-b'>Использование:</strong><br>
1) Простое использование<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;</div><div class="code_line">&nbsp;&nbsp; __int8 ret_code;</div><div class="code_line">&nbsp;&nbsp; TCHAR test_disk=_T(&#39;H&#39;);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;ret_code=IsFlashDrive(test_disk);</div><div class="code_line">&nbsp;&nbsp; if (ret_code==1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else if (ret_code==0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: НЕ является флешкой\n&quot;),test_disk);</div></ol></div></div></div></div><br>
<br>
2) Использование с минимальным контролем ошибок<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; __int8 ret_code;</div><div class="code_line">&nbsp;&nbsp; TCHAR test_disk=_T(&#39;H&#39;);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; ret_code=IsFlashDrive(test_disk);</div><div class="code_line">&nbsp;&nbsp; if (ret_code==1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else if (ret_code==0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: НЕ является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive\n&quot;),test_disk);</div></ol></div></div></div></div><br>
<br>
3)Использование с полным контролем ошибок<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; __int8 ret_code;</div><div class="code_line">&nbsp;&nbsp; TCHAR test_disk=_T(&#39;H&#39;);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; ret_code=IsFlashDrive(test_disk);</div><div class="code_line">&nbsp;&nbsp; if (ret_code==1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else if (ret_code==0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: НЕ является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (ret_code==2)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive. Ошибка CreateFile: %u\n&quot;),GetLastError());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;else if (ret_code==3)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive. Ошибка DeviceIoControl: %u\n&quot;),GetLastError());</div><div class="code_line">&nbsp;&nbsp; }</div></ol></div></div></div></div><br>
<br>
<br>
<br>
<span class='tag-size' data-value='14' style='font-size:14pt;'>2 Способ</span>(спасибо <strong class='tag-b'>ЫукпШ</strong> за наводку)<br>
<strong class='tag-b'>IsFlashDrive2</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">//Входные данные: </div><div class="code_line">// drive_letter - буква тетируемого диска</div><div class="code_line">//Выходные данные: </div><div class="code_line">// sys_err_code - код системной ошибки в случае её возникновения</div><div class="code_line">//Коды возврата:</div><div class="code_line">//0 - диск не является флешкой</div><div class="code_line">//1 - диск является флешкой</div><div class="code_line">//2,3,4,5 - ошибки</div><div class="code_line">__int8 IsFlashDrive2(TCHAR drive_letter, LONG *sys_err_code)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; __int8 ret_code=0;</div><div class="code_line">&nbsp;&nbsp; HKEY hk=NULL;</div><div class="code_line">&nbsp;&nbsp; HANDLE hdrive=INVALID_HANDLE_VALUE;</div><div class="code_line">&nbsp;&nbsp; LONG Ret;</div><div class="code_line">&nbsp;&nbsp; DWORD data_size,dtype;</div><div class="code_line">&nbsp;&nbsp; WCHAR *data=NULL;</div><div class="code_line">&nbsp;&nbsp; TCHAR dos_link[50];</div><div class="code_line">&nbsp;&nbsp; DWORD ld;</div><div class="code_line">&nbsp;&nbsp; TCHAR drive_name2[20];</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; //проверяем существует ли диск в системе</div><div class="code_line">&nbsp;&nbsp; StringCchPrintf(drive_name2,20,_T(&quot;\\.\%c:&quot;),drive_letter);</div><div class="code_line">&nbsp;&nbsp; hdrive = CreateFile(drive_name2,0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);</div><div class="code_line">&nbsp;&nbsp; if (hdrive==INVALID_HANDLE_VALUE)</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;*sys_err_code=GetLastError();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;ret_code=5;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;goto free_resources;</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">&nbsp;&nbsp; CloseHandle(hdrive);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; Ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T(&quot;SYSTEM\MountedDevices&quot;),0,KEY_READ,&amp;hk);</div><div class="code_line">&nbsp;&nbsp; if (Ret!=ERROR_SUCCESS)</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;ret_code=2;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;*sys_err_code=Ret;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;goto free_resources;</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; StringCchPrintf(dos_link,50,_T(&quot;\DosDevices\%c:&quot;),drive_letter);</div><div class="code_line">&nbsp;&nbsp; Ret=RegQueryValueEx(hk,dos_link,NULL,&amp;dtype,NULL,&amp;data_size);</div><div class="code_line">&nbsp;&nbsp; if (Ret==ERROR_SUCCESS)</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;data=(WCHAR *)malloc(data_size+2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (data==NULL)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ret_code=3;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; *sys_err_code=0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; goto free_resources;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;}</div><div class="code_line">&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;Ret=RegQueryValueEx(hk,dos_link,NULL,&amp;dtype,(LPBYTE)data,&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; ret_code=4;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; *sys_err_code=Ret;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; goto free_resources;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if(wcsstr(data,L&quot;USBSTOR&quot;)!=NULL)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ret_code=1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ret_code=0;</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;ret_code=4;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;*sys_err_code=Ret;</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">&nbsp;</div><div class="code_line">free_resources:</div><div class="code_line">&nbsp;&nbsp; if (data!=NULL) free(data);</div><div class="code_line">&nbsp;&nbsp; if (hk!=NULL) RegCloseKey(hk);</div><div class="code_line">&nbsp;&nbsp; </div><div class="code_line">&nbsp;&nbsp; return ret_code;</div><div class="code_line">}</div></ol></div></div></div></div><br>
<br>
<strong class='tag-b'>Использование</strong><br>
<br>
1) Простое использование<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; __int8 ret_code;</div><div class="code_line">&nbsp;&nbsp; TCHAR test_disk=_T(&#39;H&#39;);</div><div class="code_line">&nbsp;&nbsp; LONG sec;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; ret_code=IsFlashDrive2(test_disk,&amp;sec);</div><div class="code_line">&nbsp;&nbsp; if (ret_code==1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else if (ret_code==0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: НЕ является флешкой\n&quot;),test_disk);</div></ol></div></div></div></div>   <br>
<br>
<br>
2) Использование с минимальным контролем ошибок<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; __int8 ret_code;</div><div class="code_line">&nbsp;&nbsp; TCHAR test_disk=_T(&#39;H&#39;);</div><div class="code_line">&nbsp;&nbsp; LONG sec;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; ret_code=IsFlashDrive2(test_disk,&amp;sec);</div><div class="code_line">&nbsp;&nbsp; if (ret_code==1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else if (ret_code==0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: НЕ является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive2\n&quot;),test_disk);</div></ol></div></div></div></div><br>
<br>
<br>
3) Использование с полным контролем ошибок<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; __int8 ret_code;</div><div class="code_line">&nbsp;&nbsp; TCHAR test_disk=_T(&#39;H&#39;);</div><div class="code_line">&nbsp;&nbsp; LONG sec;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; ret_code=IsFlashDrive2(test_disk,&amp;sec);</div><div class="code_line">&nbsp;&nbsp; if (ret_code==1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else if (ret_code==0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: НЕ является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (ret_code==2)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive2. Ошибка RegOpenKeyEx: %u\n&quot;),sec);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;else if (ret_code==3)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive2. Ошибка malloc.\n&quot;));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;else if (ret_code==4)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive2. Ошибка RegQueryValueEx: %u\n&quot;),sec);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;else if (ret_code==5)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive2. Ошибка CreateFile: %u\n&quot;),sec);</div><div class="code_line">&nbsp;&nbsp; }</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">#ifndef UNICODE</div><div class="code_line">#define UNICODE</div><div class="code_line">#endif</div><div class="code_line">#ifndef _UNICODE</div><div class="code_line">#define _UNICODE</div><div class="code_line">#endif</div><div class="code_line">&nbsp;</div><div class="code_line">#include &#60;tchar.h&#62;</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">#include &#60;StrSafe.h&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">//--------------------------------------------------------------------------------------------------------------------------</div><div class="code_line">//Входные данные: </div><div class="code_line">//IN drive_letter - буква тетируемого диска</div><div class="code_line">//Коды возврата:</div><div class="code_line">//0 - диск не является флешкой</div><div class="code_line">//1 - диск является флешкой</div><div class="code_line">//2,3 - ошибки</div><div class="code_line">__int8 IsFlashDrive(TCHAR drive_letter)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; UINT drive_type;</div><div class="code_line">&nbsp;&nbsp; STORAGE_PROPERTY_QUERY spq;</div><div class="code_line">&nbsp;&nbsp; STORAGE_DEVICE_DESCRIPTOR sdd;</div><div class="code_line">&nbsp;&nbsp; DWORD BytesReturned;</div><div class="code_line">&nbsp;&nbsp; HANDLE hdrive=INVALID_HANDLE_VALUE;</div><div class="code_line">&nbsp;&nbsp; TCHAR drive_name1[20],drive_name2[20];</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; StringCchPrintf(drive_name1,20,_T(&quot;%c:\&quot;),drive_letter);</div><div class="code_line">&nbsp;&nbsp; StringCchPrintf(drive_name2,20,_T(&quot;\\.\%c:&quot;),drive_letter);</div><div class="code_line">&nbsp;&nbsp;</div><div class="code_line">&nbsp;&nbsp; drive_type=GetDriveType(drive_name1);</div><div class="code_line">&nbsp;&nbsp; </div><div class="code_line">&nbsp;&nbsp; hdrive = CreateFile(drive_name2,0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);</div><div class="code_line">&nbsp;&nbsp; if (hdrive==INVALID_HANDLE_VALUE)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;return 2;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; memset(&amp;spq,0,sizeof(spq));</div><div class="code_line">&nbsp;&nbsp; memset(&amp;sdd,0,sizeof(sdd));</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; spq.PropertyId=StorageDeviceProperty;</div><div class="code_line">&nbsp;&nbsp; spq.QueryType=PropertyStandardQuery;</div><div class="code_line">&nbsp;&nbsp; if (!DeviceIoControl(hdrive,IOCTL_STORAGE_QUERY_PROPERTY,&amp;spq,sizeof(spq),&amp;sdd,sizeof(sdd),&amp;BytesReturned,NULL))</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; CloseHandle(hdrive);</div><div class="code_line">&nbsp;&nbsp; &nbsp; return 3;</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; CloseHandle(hdrive);</div><div class="code_line">&nbsp;&nbsp; if ((drive_type==DRIVE_REMOVABLE)&amp;&amp;(sdd.BusType==BusTypeUsb)&amp;&amp;(sdd.RemovableMedia==true))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;return 1;</div><div class="code_line">&nbsp;&nbsp; else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;return 0;</div><div class="code_line">}</div><div class="code_line">//--------------------------------------------------------------------------------------------------------------------------</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">//--------------------------------------------------------------------------------------------------------------------------</div><div class="code_line">//Входные данные: </div><div class="code_line">//IN drive_letter - буква тетируемого диска</div><div class="code_line">//OUT sys_err_code - код системной ошибки в случае её возникновения</div><div class="code_line">//Коды возврата:</div><div class="code_line">//0 - диск не является флешкой</div><div class="code_line">//1 - диск является флешкой</div><div class="code_line">//2,3,4,5 - ошибки</div><div class="code_line">__int8 IsFlashDrive2(TCHAR drive_letter, LONG *sys_err_code)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; __int8 ret_code=0;</div><div class="code_line">&nbsp;&nbsp; HKEY hk=NULL;</div><div class="code_line">&nbsp;&nbsp; HANDLE hdrive=INVALID_HANDLE_VALUE;</div><div class="code_line">&nbsp;&nbsp; LONG Ret;</div><div class="code_line">&nbsp;&nbsp; DWORD data_size,dtype;</div><div class="code_line">&nbsp;&nbsp; WCHAR *data=NULL;</div><div class="code_line">&nbsp;&nbsp; TCHAR dos_link[50];</div><div class="code_line">&nbsp;&nbsp; TCHAR drive_name2[20];</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; //проверяем существует ли диск в системе</div><div class="code_line">&nbsp;&nbsp; StringCchPrintf(drive_name2,20,_T(&quot;\\.\%c:&quot;),drive_letter);</div><div class="code_line">&nbsp;&nbsp; hdrive = CreateFile(drive_name2,0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);</div><div class="code_line">&nbsp;&nbsp; if (hdrive==INVALID_HANDLE_VALUE)</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;*sys_err_code=GetLastError();</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;ret_code=5;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;goto free_resources;</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">&nbsp;&nbsp; CloseHandle(hdrive);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; Ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T(&quot;SYSTEM\MountedDevices&quot;),0,KEY_READ,&amp;hk);</div><div class="code_line">&nbsp;&nbsp; if (Ret!=ERROR_SUCCESS)</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;ret_code=2;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;*sys_err_code=Ret;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;goto free_resources;</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; StringCchPrintf(dos_link,50,_T(&quot;\DosDevices\%c:&quot;),drive_letter);</div><div class="code_line">&nbsp;&nbsp; Ret=RegQueryValueEx(hk,dos_link,NULL,&amp;dtype,NULL,&amp;data_size);</div><div class="code_line">&nbsp;&nbsp; if (Ret==ERROR_SUCCESS)</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;data=(WCHAR *)malloc(data_size+2);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (data==NULL)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ret_code=3;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; *sys_err_code=0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; goto free_resources;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;}</div><div class="code_line">&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;Ret=RegQueryValueEx(hk,dos_link,NULL,&amp;dtype,(LPBYTE)data,&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; ret_code=4;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; *sys_err_code=Ret;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; goto free_resources;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if(wcsstr(data,L&quot;USBSTOR&quot;)!=NULL)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ret_code=1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; ret_code=0;</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;ret_code=4;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;*sys_err_code=Ret;</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">&nbsp;</div><div class="code_line">free_resources:</div><div class="code_line">&nbsp;&nbsp; if (data!=NULL) free(data);</div><div class="code_line">&nbsp;&nbsp; if (hk!=NULL) RegCloseKey(hk);</div><div class="code_line">&nbsp;&nbsp; </div><div class="code_line">&nbsp;&nbsp; return ret_code;</div><div class="code_line">}</div><div class="code_line">//--------------------------------------------------------------------------------------------------------------------------</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">//--------------------------------------------------------------------------------------------------------------------------</div><div class="code_line">int _tmain(int argc, _TCHAR* argv[])</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; __int8 ret_code;</div><div class="code_line">&nbsp;&nbsp; TCHAR test_disk=_T(&#39;H&#39;);</div><div class="code_line">&nbsp;&nbsp; LONG sec;</div><div class="code_line">&nbsp;</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; //IsFlashDrive</div><div class="code_line">&nbsp;&nbsp; //Простое использование</div><div class="code_line">&nbsp;&nbsp; ret_code=IsFlashDrive(test_disk);</div><div class="code_line">&nbsp;&nbsp; if (ret_code==1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else if (ret_code==0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: НЕ является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; </div><div class="code_line">&nbsp;&nbsp; //Использование с минимальным контролем ошибок</div><div class="code_line">&nbsp;&nbsp; ret_code=IsFlashDrive(test_disk);</div><div class="code_line">&nbsp;&nbsp; if (ret_code==1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else if (ret_code==0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: НЕ является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive\n&quot;),test_disk);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; //Использование с полным контролем ошибок</div><div class="code_line">&nbsp;&nbsp; ret_code=IsFlashDrive(test_disk);</div><div class="code_line">&nbsp;&nbsp; if (ret_code==1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else if (ret_code==0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: НЕ является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (ret_code==2)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive. Ошибка CreateFile: %u\n&quot;),GetLastError());</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;else if (ret_code==3)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive. Ошибка DeviceIoControl: %u\n&quot;),GetLastError());</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; //IsFlashDrive2</div><div class="code_line">&nbsp;&nbsp; //Простое использование</div><div class="code_line">&nbsp;&nbsp; ret_code=IsFlashDrive2(test_disk,&amp;sec);</div><div class="code_line">&nbsp;&nbsp; if (ret_code==1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else if (ret_code==0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: НЕ является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; //Использование с минимальным контролем ошибок</div><div class="code_line">&nbsp;&nbsp; ret_code=IsFlashDrive2(test_disk,&amp;sec);</div><div class="code_line">&nbsp;&nbsp; if (ret_code==1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else if (ret_code==0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: НЕ является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive2\n&quot;),test_disk);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; //Использование с полным контролем ошибок</div><div class="code_line">&nbsp;&nbsp; ret_code=IsFlashDrive2(test_disk,&amp;sec);</div><div class="code_line">&nbsp;&nbsp; if (ret_code==1)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else if (ret_code==0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Диск %c: НЕ является флешкой\n&quot;),test_disk);</div><div class="code_line">&nbsp;&nbsp; else</div><div class="code_line">&nbsp;&nbsp; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if (ret_code==2)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive2. Ошибка RegOpenKeyEx: %u\n&quot;),sec);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;else if (ret_code==3)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive2. Ошибка malloc.\n&quot;));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;else if (ret_code==4)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive2. Ошибка RegQueryValueEx: %u\n&quot;),sec);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;else if (ret_code==5)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;_tprintf(_T(&quot;Ошибка IsFlashDrive2. Ошибка CreateFile: %u\n&quot;),sec);</div><div class="code_line">&nbsp;&nbsp; }</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; _tprintf(_T(&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><div class="code_line">//--------------------------------------------------------------------------------------------------------------------------</div></ol></div></div></div></div>]]></description>
        <author>neokoder</author>
        <category>C/C++: Системное программирование и WinAPI</category>
      </item>
	
      </channel>
      </rss>
	