<?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="https://forum.script-coding.com/extern.php?action=feed&amp;tid=8262&amp;type=atom" />
	<updated>2013-06-19T12:51:27Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=8262</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73114#p73114" />
			<content type="html"><![CDATA[<p>Спасибо за развернутое объяснение.<br />Начал понимать <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />Сейчас фрагмент кода по выгружению usb выглядит так и вроде работает<br /></p><div class="codebox"><pre><code>
copyDest = Z:
watchfolder = D:\Abola\TEMP_HDD
FileRemoveDir, %watchfolder%, 1
FileCreateDir, %watchfolder%
FileAppend, list volume, %watchfolder%\hdd1.txt
Runwait, %comspec% /c &quot;&quot;DISKPART.exe&quot; &quot;/s&quot; &quot;%watchfolder%\hdd1.txt&quot; &gt; &quot;%watchfolder%\hdd2.txt&quot;&quot;
FileRead, DiskPart, %watchfolder%\hdd2.txt
RegExMatch(DiskPart, &quot;\R\s+Volume\s+(\d+)\s+\w\s+USB_HDD\s+&quot;, Match)
FileAppend, select volume %Match1%`nremove all dismount, %watchfolder%\hdd3.txt
Runwait, %comspec% /c &quot;&quot;DISKPART.exe&quot; &quot;/s&quot; &quot;%watchfolder%\hdd3.txt&quot;&quot;
FileAppend, select volume %Match1%`nassign letter=%copyDest%, %watchfolder%\hdd4.txt
Runwait, %comspec% /c &quot;&quot;DISKPART.exe&quot; &quot;/s&quot; &quot;%watchfolder%\hdd4.txt&quot;&quot;
FileRemoveDir, %watchfolder%, 1
RunWait, D:\Abola\USB_HDD\RemUMS.exe %copyDest%   ; безопасно выгружаем usb
MsgBox, 4096, USB_HDD, DONE!
ExitApp 
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2013-06-19T12:51:27Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73114#p73114</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73104#p73104" />
			<content type="html"><![CDATA[<p>Шаблон можно поправить на:<br /></p><div class="codebox"><pre><code>&quot;\R\s+Volume\s+(\d+)\s+(\w)\s+Backup\s+&quot;</code></pre></div><p>Тут всё очень просто: Ищется строка указанная в шаблоне.<br />То есть кусок текста из переменной где подряд идут:<br />\R - перенос строки<br />\s+ - один и более пробельных символов<br />Volume - слово Volume<br />\s+ - один и более пробельных символов<br />\d+ - одна и более цифр<br />\s+ - один и более пробельных символов<br />\w - одна буква<br />\s+ - один и более пробельных символов<br />Backup - слово Backup<br />\s+ - один и более пробельных символов</p><p><span class="bbu">Так как:</span><br />\d+ заключена в скобки, её содержимое в найденной подстроке будет в Match1.<br />\w заключена в скобки после \d+, её содержимое будет в Match2.<br />Сама найденная строка в Match.</p><div class="codebox"><pre><code>RegExMatch(DiskPart, &quot;\R\s+Volume\s+(\d+)\s+(\w)\s+Backup\s+&quot;, Match)
MsgBox % Match
MsgBox % Match1
MsgBox % Match2</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-06-19T09:55:18Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73104#p73104</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73098#p73098" />
			<content type="html"><![CDATA[<p>Спасибо огромное!<br />Я к сожалению RegEx не понимаю.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2013-06-19T09:32:20Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73098#p73098</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73095#p73095" />
			<content type="html"><![CDATA[<p>Номер же надо, а не букву.<br /></p><div class="codebox"><pre><code>RegExMatch(DiskPart, &quot;.*?\R\s+Volume\s+(\d+)\s+(\w)\s+Backup\s+.*&quot;, Match)
MsgBox % Match1
MsgBox % Match2

</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-06-19T09:23:47Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73095#p73095</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73093#p73093" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>
DiskPart =
(
Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: TV-PC

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     X                       DVD-ROM         0 B  No Media           
  Volume 1         System Rese  NTFS   Partition    100 MB  Healthy    System  
  Volume 2     C                NTFS   Partition    465 GB  Healthy    Boot    
  Volume 3     D                NTFS   Partition    931 GB  Healthy    Pagefile
  Volume 4     G   Backup       NTFS   Partition   2794 GB  Healthy            
  Volume 5     F   Backup       NTFS   Partition   2794 GB  Healthy            
  Volume 6                             Partition   2794 GB  Healthy    Offline 
)
RegExMatch(DiskPart, &quot;.*?\R\s+Volume\s+\d+\s+(\w)\s+Backup\s+.*&quot;, Match)
MsgBox % Match1
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-06-19T09:20:32Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73093#p73093</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73091#p73091" />
			<content type="html"><![CDATA[<p>Вот, что удалось написать<br /></p><div class="codebox"><pre><code>watchfolder = C:\1
FileRemoveDir, %watchfolder%, 1
FileCreateDir, %watchfolder%
FileAppend, list volume, %watchfolder%\hdd.txt
Run, %comspec% /c &quot;&quot;DISKPART.exe&quot; &quot;/s&quot; &quot;%watchfolder%\hdd.txt&quot; &gt; &quot;%watchfolder%\volumes.txt&quot;&quot;
WinWaitClose, ahk_class ConsoleWindowClass
sleep 1000

; получаем букву диска в переменную var
; Loop, read, %watchfolder%\volumes.txt

FileAppend, select volume %var%`nremove all dismount`nexit, %watchfolder%\hdd1.txt
Run, %comspec% /c &quot;&quot;DISKPART.exe&quot; &quot;/s&quot; &quot;%watchfolder%\hdd.txt&quot;&quot;
WinWaitClose, ahk_class ConsoleWindowClass
msgbox, DONE</code></pre></div><p>Но никак не получается распарсить инфу с CMD.<br />Помогите, пожалуйста, вытащить номер volume первого диска с лейблом Backup.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2013-06-19T09:10:56Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73091#p73091</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=73062#p73062" />
			<content type="html"><![CDATA[<p>Не подходят эти варианты - не вытаскивается.<br />Единственный рабочий вариант нашел:</p><p>&nbsp; &nbsp; Type <strong>diskpart</strong> and wait for the diskpart prompt (DISKPART&gt;)</p><p>&nbsp; &nbsp; Type<strong> list volume</strong></p><p>&nbsp; &nbsp; Note the volume number of the USB drive carefully (use listed properties such as drive letter, label, type and size for help)</p><p>&nbsp; &nbsp; Type <strong>select volume &lt;number&gt;</strong>, where &lt;number&gt; is the volume number noted above</p><p>&nbsp; &nbsp; Type <strong>remove all dismount</strong></p><p>&nbsp; &nbsp; Type <strong>exit</strong> to quit Diskpart</p><p>&nbsp; &nbsp;Now you should be able to safely remove your USB drive without fear of data loss.</p><p>Как мне это все забабахать через autohotkey, зная лейбл диска?<br />Пока написал вот это<br /></p><div class="codebox"><pre><code>Run, %comspec% /c DISKPART.exe /s C:hdd.txt &gt; C:volumes.txt</code></pre></div><p>а в hdd.txt<br /></p><div class="codebox"><pre><code>list volume</code></pre></div><p>На выходе получаем</p><p>Microsoft DiskPart version 6.1.7601<br />Copyright (C) 1999-2008 Microsoft Corporation.<br />On computer: TV-PC</p><div class="quotebox"><blockquote><p>Volume ###&nbsp; Ltr&nbsp; Label&nbsp; &nbsp; &nbsp; &nbsp; Fs&nbsp; &nbsp; &nbsp;Type&nbsp; &nbsp; &nbsp; &nbsp; Size&nbsp; &nbsp; &nbsp;Status&nbsp; &nbsp; &nbsp;Info<br />&nbsp; ----------&nbsp; ---&nbsp; -----------&nbsp; -----&nbsp; ----------&nbsp; -------&nbsp; ---------&nbsp; --------<br />&nbsp; Volume 0&nbsp; &nbsp; &nbsp;X&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DVD-ROM&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 B&nbsp; No Media&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />&nbsp; Volume 1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System Rese&nbsp; NTFS&nbsp; &nbsp;Partition&nbsp; &nbsp; 100 MB&nbsp; Healthy&nbsp; &nbsp; System&nbsp; <br />&nbsp; Volume 2&nbsp; &nbsp; &nbsp;C&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NTFS&nbsp; &nbsp;Partition&nbsp; &nbsp; 465 GB&nbsp; Healthy&nbsp; &nbsp; Boot&nbsp; &nbsp; <br />&nbsp; Volume 3&nbsp; &nbsp; &nbsp;D&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NTFS&nbsp; &nbsp;Partition&nbsp; &nbsp; 931 GB&nbsp; Healthy&nbsp; &nbsp; Pagefile<br />&nbsp; Volume 4&nbsp; &nbsp; &nbsp;G&nbsp; &nbsp;Backup&nbsp; &nbsp; &nbsp; &nbsp;NTFS&nbsp; &nbsp;Partition&nbsp; &nbsp;2794 GB&nbsp; Healthy&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; Volume 5&nbsp; &nbsp; &nbsp;F&nbsp; &nbsp;Backup&nbsp; &nbsp; &nbsp; &nbsp;NTFS&nbsp; &nbsp;Partition&nbsp; &nbsp;2794 GB&nbsp; Healthy&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; Volume 6&nbsp; &nbsp; &nbsp;Z&nbsp; &nbsp;Usb&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Partition&nbsp; &nbsp;2794 GB&nbsp; Healthy</p></blockquote></div><br /><p>По идее, чтобы узнать номер диска надо обрабатывать volumes.txt<br />А обрабатывать его тогда надо в hdd.txt?<br />Как-то все непонятно.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2013-06-18T20:08:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=73062#p73062</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=71707#p71707" />
			<content type="html"><![CDATA[<p>Вот тут из-за этой битности у меня код teadrinker не срабатывал.<br /><a href="http://forum.script-coding.com/viewtopic.php?id=6093&amp;p=3">http://forum.script-coding.com/viewtopi … 93&amp;p=3</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2013-04-28T00:22:27Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=71707#p71707</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=71704#p71704" />
			<content type="html"><![CDATA[<p>Коды с autohotkey.com у меня тоже не работают.<br />Код из справки я проверил, во время копирования он не извлекает девайс, значит это безопасное извлечение, наверное.</p><p>Давно хотел у кого нибудь спросить, а зачем вообще использовать ахк 64 бит?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-04-27T23:39:47Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=71704#p71704</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=71703#p71703" />
			<content type="html"><![CDATA[<p>А у меня код из справки не работает, может потому, что ахк 64 бит.<br />Аналогично&nbsp; gAHK32&nbsp; тоже не работает.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2013-04-27T23:27:01Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=71703#p71703</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=71701#p71701" />
			<content type="html"><![CDATA[<p>У меня код из справки работает:<br /></p><div class="codebox"><pre><code>Driveletter = G:  ; Set this to the drive letter you wish to eject.

hVolume := DllCall(&quot;CreateFile&quot;
    , Str, &quot;\\.\&quot; . Driveletter
    , UInt, 0x80000000 | 0x40000000  ; GENERIC_READ | GENERIC_WRITE
    , UInt, 0x1 | 0x2  ; FILE_SHARE_READ | FILE_SHARE_WRITE
    , UInt, 0
    , UInt, 0x3  ; OPEN_EXISTING
    , UInt, 0, UInt, 0)
if hVolume &lt;&gt; -1
{
    DllCall(&quot;DeviceIoControl&quot;
        , UInt, hVolume
        , UInt, 0x2D4808   ; IOCTL_STORAGE_EJECT_MEDIA
        , UInt, 0, UInt, 0, UInt, 0, UInt, 0
        , UIntP, dwBytesReturned  ; Unused.
        , UInt, 0)
    DllCall(&quot;CloseHandle&quot;, UInt, hVolume)
} </code></pre></div><p>правда я не знаю безопасное ли это извлечение?</p><p>Ещё можно покурить:<br /><a href="http://www.autohotkey.com/board/topic/80486-solved-get-hardware-serial-no-of-usb-stick/?hl=cm_request_device_eject">http://www.autohotkey.com/board/topic/8 … vice_eject</a> </p><p><a href="http://www.autohotkey.com/board/topic/41310-safelyremoveums-safely-remove-usb-mass-storage-drives/?hl=cm_request_device_eject">http://www.autohotkey.com/board/topic/4 … vice_eject</a></p><p>ну и:<br /><a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff539806">http://msdn.microsoft.com/en-us/library … e/ff539806</a></p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-04-27T19:00:16Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=71701#p71701</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=71700#p71700" />
			<content type="html"><![CDATA[<p>Речь про USB диск, который хочутся отключить после бекапа.<br />У диска постоянная буква.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2013-04-27T18:01:24Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=71700#p71700</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=71699#p71699" />
			<content type="html"><![CDATA[<p>То есть просто путь? Речь только про флэшки?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-04-27T17:52:43Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=71699#p71699</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=71698#p71698" />
			<content type="html"><![CDATA[<p>Проклятая невнимательность <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /><br /></p><div class="quotebox"><blockquote><p>А в принципе, как указывать устройство для извлечения?</p></blockquote></div><p>В скрипте по ссылке очень удобно.<br />Нужно лишь вписать в скрипт<br /></p><div class="codebox"><pre><code>RemUMS D:\ </code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2013-04-27T17:50:35Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=71698#p71698</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Безопасно вытащить USB]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=71696#p71696" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>Бузопасно вытащить USB</p></blockquote></div><p>Я бы сменил на:<br /></p><div class="quotebox"><blockquote><p>AHK: Безопасно вытащить USB</p></blockquote></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2013-04-27T17:36:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=71696#p71696</id>
		</entry>
</feed>
