<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Отключение USB дисков при загрузке системы.]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=17683&amp;type=atom" />
	<updated>2023-03-13T08:57:15Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=17683</id>
		<entry>
			<title type="html"><![CDATA[AHK: Отключение USB дисков при загрузке системы.]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=157153#p157153" />
			<content type="html"><![CDATA[<p>В журнале событий при каждой загрузке Win7 появляется ошибка на сата контроллере - &quot;Event ID 11, Disk: The driver detected a controller error&quot;.<br />Опытным путем выяснил, что причина этого в том, что при загрузке винды подключен usb hdd.<br />Пробовал менять драйверы, отключать загрузку с usb в биосе - ничего не помогает.<br />Решил тогда отключать usb hdd при загрузке виндовса, а включать через 10 секунд и деактивировать/активировать USB устройства.<br /></p><div class="codebox"><pre><code>deviceDescription := &quot;USB Mass Storage Device&quot;

#NoTrayIcon
#SingleInstance force
OnMessage(0x11, &quot;WM_QUERYENDSESSION&quot;)
OnExit, ExitSub
RegRead, OutputVar, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR, Start
if (OutputVar != 3)
{
   sleep 10000
   RegWrite, REG_DWORD, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR, Start, 3
   hModule := DllCall(&quot;LoadLibrary&quot;, &quot;Str&quot;, &quot;setupapi.dll&quot;, &quot;Ptr&quot;)
   info := DllCall(&quot;setupapi.dll\SetupDiGetClassDevs&quot;, &quot;Ptr&quot;, 0, &quot;Str&quot;, &quot;USB&quot;, &quot;Ptr&quot;, 0, &quot;UInt&quot;, 0x00000002|0x00000004, &quot;Ptr&quot;)   ; DIGCF_PRESENT | DIGCF_ALLCLASSES
   if (info = -1)
   {
      Msgbox % &quot;SetupDiGetClassDevs failed: &quot; A_LastError
      ExitApp
   }
   VarSetCapacity(SP_DEVINFO_DATA, 24+A_PtrSize, 0)
   NumPut(24+A_PtrSize, SP_DEVINFO_DATA, 0, &quot;UInt&quot;)
   Loop
   {
      If !DllCall(&quot;setupapi.dll\SetupDiEnumDeviceInfo&quot;, &quot;Ptr&quot;, info, &quot;UInt&quot;, A_Index-1, &quot;Ptr&quot;, &amp;SP_DEVINFO_DATA)
      {
         If (A_LastError != 259) ;ERROR_NO_MORE_ITEMS
         {
            MsgBox % &quot;SetupDiEnumDeviceInfo failed: &quot; A_LastError
            ExitApp
         }
         break
      }
      VarSetCapacity(buf, 512, 0)
      VarSetCapacity(strsz, 4, 0)
      r := DllCall(&quot;setupapi.dll\SetupDiGetDeviceRegistryPropertyW&quot;, &quot;ptr&quot;, info, &quot;ptr&quot;, &amp;SP_DEVINFO_DATA, &quot;uint&quot;, SPDRP_DEVICEDESC := 0, &quot;ptr&quot;, 0, &quot;ptr&quot;, &amp;buf, &quot;uint&quot;, 512, &quot;ptr&quot;, &amp;strsz)
      if !r and (A_LastError != 13)   ; ERROR_INVALID_DATA
      {
         Msgbox % &quot;SetupDiGetDeviceRegistryProperty failed: &quot; A_LastError
         ExitApp
      }
      description := StrGet(&amp;buf, NumGet(strsz, &quot;uint&quot;))
      if (description = deviceDescription)
      {
         VarSetCapacity(status, 4, 0)
         VarSetCapacity(error, 4, 0)
         if r := DllCall(&quot;setupapi.dll\CM_Get_DevNode_Status&quot;, &quot;ptr&quot;, &amp;status, &quot;ptr&quot;, &amp;error, &quot;uint&quot;, NumGet(SP_DEVINFO_DATA, 20 ,&quot;uint&quot;), &quot;uint&quot;, 0)
         {
            Msgbox % &quot;CM_Get_DevNode_Status failed: &quot; r
            ExitApp
         }
         flags := NumGet(status,0,&quot;uint&quot;)
         if (flags &amp; 0x00000400) ; DN_HAS_PROBLEM
         {
            loop 2
            {
               VarSetCapacity(ClassInstallParams, 20, 0)
               Numput(8, ClassInstallParams, 0, &quot;uint&quot;)
               Numput(DIF_PROPERTYCHANGE := 0x12, ClassInstallParams, 4, &quot;uint&quot;)
               Numput(3 - A_Index, ClassInstallParams, 8, &quot;uint&quot;)
               Numput(DICS_FLAG_GLOBAL := 1, ClassInstallParams, 12, &quot;uint&quot;)
               Numput(0, ClassInstallParams, 16, &quot;uint&quot;)
               if !DllCall(&quot;setupapi.dll\SetupDiSetClassInstallParams&quot;, &quot;ptr&quot;, info, &quot;ptr&quot;, &amp;SP_DEVINFO_DATA, &quot;ptr&quot;, &amp;ClassInstallParams, &quot;uint&quot;, 20)
               {
                  Msgbox % &quot;SetupDiSetClassInstallParams failed: &quot; A_LastError
                  ExitApp
               }
               if !DllCall(&quot;setupapi.dll\SetupDiChangeState&quot;, &quot;ptr&quot;, info, &quot;ptr&quot;, &amp;SP_DEVINFO_DATA)
               {
                  Msgbox % &quot;SetupDiChangeState failed: &quot; A_LastError
                  ExitApp
               }
            }
         }
      }   
   }
}
return

ExitSub:
DllCall(&quot;setupapi.dll\SetupDiDestroyDeviceInfoList&quot;, &quot;ptr&quot;, info)
DllCall(&quot;FreeLibrary&quot;, &quot;Ptr&quot;, hModule)
ExitApp


WM_QUERYENDSESSION()
{
   RegWrite, REG_DWORD, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR, Start, 4
   Return true
}</code></pre></div><p><a href="http://forum.script-coding.com/viewtopic.php?id=14863">Тема для обсуждения</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2023-03-13T08:57:15Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=157153#p157153</id>
		</entry>
</feed>
