{"id":335,"date":"2007-08-23T02:35:00","date_gmt":"2007-08-23T09:35:00","guid":{"rendered":"https:\/\/kb.terabyteunlimited.com\/kb-articles\/selecting-a-hard-drive-from-a-windows-command-script\/"},"modified":"2021-09-10T14:29:05","modified_gmt":"2021-09-10T21:29:05","slug":"selecting-a-hard-drive-from-a-windows-command-script","status":"publish","type":"lsvr_kba","link":"https:\/\/www.terabyteunlimited.com\/kb\/kb-articles\/selecting-a-hard-drive-from-a-windows-command-script\/","title":{"rendered":"Selecting a Hard Drive from a Windows Command Script"},"content":{"rendered":"<p>The Windows 2000+ command script shown below uses the TeraByte Unlimited <a href=\"http:\/\/www.terabyteunlimited.com\/downloads\/EMBR_NT.ZIP\">EMBR_NT.EXE utility<\/a> to (in effect) present a hard drive selection menu. Such a menu could be used for any purpose where a Windows command script is being run and a hard drive number needs to be selected.\u00a0 For example, after some customization, the script could be used to allow a hard drive number to be selected prior to performing a restore to it using <a href=\"https:\/\/www.terabyteunlimited.com\/image-for-windows\/\" target=\"_blank\" rel=\"noopener\">Image for Windows<\/a>.<br \/>\r\n<br \/>\r\nBy default, the script queries hard drive numbers 0 through 9. For any drive where the query succeeds, the EMBR_NT.EXE utility displays basic information relating to the partitions\/volumes present on that drive (name, size, type, ID, file system). If a drive does not exist, the utility displays a simple error message (\"Error: Unable to open hard drive N.\").<br \/>\r\n<br \/>\r\nBeyond presenting the menu described, this script performs no actions. Where indicated near the bottom of the script, you can add your own code to perform whatever action is desired with the selected hard drive number.<br \/>\r\n<br \/>\r\nThe EMBR_NT.EXE utility can be obtained from the following links:<br \/>\r\n<br \/>\r\n<a href=\"http:\/\/www.terabyteunlimited.com\/downloads\/EMBR_NT.ZIP\" target=\"_self\" rel=\"noopener\">http:\/\/www.terabyteunlimited.com\/downloads\/EMBR_NT.ZIP<\/a><br \/>\r\n<a href=\"ftp:\/\/www.terabyteunlimited.com\/EMBR_NT.ZIP\">ftp:\/\/www.terabyteunlimited.com\/EMBR_NT.ZIP<\/a><br \/>\r\n<br \/>\r\nThe script begins below. To use it, select all applicable text below and paste it into a text editor such as Notepad. Then save it with the .BAT or .CMD extension.<br \/>\r\n<br \/>\r\n@echo off &amp; cls &amp; setlocal<br \/>\r\n<br \/>\r\n::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::<br \/>\r\n:: This Windows 2000+ command script uses the TeraByte Unlimited EMBR_NT.EXE utility<br \/>\r\n:: to (in effect) present a hard drive selection menu. By default, the script queries<br \/>\r\n:: hard drive numbers 0 through 9. For any drive where the query succeeds, the<br \/>\r\n:: EMBR_NT.EXE utility displays basic information relating to the partitions\/volumes<br \/>\r\n:: present on that drive (name, size, type, ID, file system). If a drive does not exist,<br \/>\r\n:: the utility displays a simple error message (\"Error: Unable to open hard drive N.\").<br \/>\r\n::<br \/>\r\n:: Beyond presenting the menu described, this script performs no actions. Where indicated<br \/>\r\n:: near the bottom of the script, you can add your own code to perform whatever action<br \/>\r\n:: is desired with the selected hard drive number.<br \/>\r\n::<br \/>\r\n:: The EMBR_NT.EXE utility can be obtained from the following links:<br \/>\r\n::<br \/>\r\n:: http:\/\/www.terabyteunlimited.com\/downloads\/EMBR_NT.ZIP<br \/>\r\n:: ftp:\/\/www.terabyteunlimited.com\/EMBR_NT.ZIP<br \/>\r\n::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::<br \/>\r\n<br \/>\r\n:: Check that the script is running under a proper version of Windows:<br \/>\r\nver | find \"Version 5.\" &gt;nul<br \/>\r\nset VerCheck1=%ErrorLevel%<br \/>\r\nver | find \"Version 6.\" &gt;nul<br \/>\r\nset VerCheck2=%ErrorLevel%<br \/>\r\nset VerCheck=%VerCheck1%%VerCheck2%<br \/>\r\nif \"%VerCheck%\"==\"11\" (<br \/>\r\n\u00a0\u00a0 cls<br \/>\r\n\u00a0\u00a0 echo.<br \/>\r\n\u00a0\u00a0 echo Error running %0:<br \/>\r\n\u00a0\u00a0 echo.<br \/>\r\n\u00a0\u00a0 echo This script runs only under Windows 2000 or later.<br \/>\r\n\u00a0\u00a0 echo.<br \/>\r\n\u00a0\u00a0 pause<br \/>\r\n\u00a0\u00a0 goto :EOF\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 )<br \/>\r\n<br \/>\r\n:: Check for the existence of EMBR_NT.EXE:<br \/>\r\nembr_nt.exe &gt;nul 2&gt;&amp;1<br \/>\r\nif ErrorLevel 9009 (<br \/>\r\n\u00a0\u00a0 cls<br \/>\r\n\u00a0\u00a0 echo.<br \/>\r\n\u00a0\u00a0 echo Error running %0:<br \/>\r\n\u00a0\u00a0 echo.<br \/>\r\n\u00a0\u00a0 echo EMBR_NT.EXE was not found. The utility may be downloaded here:<br \/>\r\n\u00a0\u00a0 echo.<br \/>\r\n\u00a0\u00a0 echo http:\/\/www.terabyteunlimited.com\/downloads\/EMBR_NT.ZIP<br \/>\r\n\u00a0\u00a0 echo ftp:\/\/www.terabyteunlimited.com\/EMBR_NT.ZIP<br \/>\r\n\u00a0\u00a0 echo.<br \/>\r\n\u00a0\u00a0 echo Place EMBR_NT.EXE in a folder that is in the system path.<br \/>\r\n\u00a0\u00a0 echo %WinDir% is generally the best choice, for simplicity.<br \/>\r\n\u00a0\u00a0 echo.<br \/>\r\n\u00a0\u00a0 pause<br \/>\r\n\u00a0\u00a0 goto :EOF\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 )<br \/>\r\n<br \/>\r\n:: Building the hard drive selection menu:<br \/>\r\necho.<br \/>\r\necho ###################################################<br \/>\r\necho Enter a number to select hard drive:<br \/>\r\n<br \/>\r\n:: If desired, you can make the script stop querying hard drives beyond a certain number.<br \/>\r\n:: For example, to query only hard drive numbers 0, 1, and 2, use \"(0,1,2)\" below, rather<br \/>\r\n:: than the default of \"(0,1,9)\". There is no harm in querying non-existent hard drive<br \/>\r\n:: numbers, but for any non-existent drive number that is queried, an error will display.<br \/>\r\nfor \/l %%a in (0,1,9) do call :CheckDrives %%a<br \/>\r\n<br \/>\r\n:: The line below is not executed until after all hard drives have been queried:<br \/>\r\ngoto :PostCheckDrives<br \/>\r\n<br \/>\r\n:: The hard drive query loop begins with the line below (\"call :CheckDrives\"):<br \/>\r\n:CheckDrives<br \/>\r\n<br \/>\r\nset #=%1<br \/>\r\nif \"%#%\"==\"\" goto :EOF<br \/>\r\n<br \/>\r\necho ---------------------------------------------------<br \/>\r\necho Hard Drive [%#%]:<br \/>\r\necho.<br \/>\r\n<br \/>\r\nembr_nt.exe %#% lis<br \/>\r\n<br \/>\r\n:: The \"goto :EOF\" below just stops the loop, not the whole script:<br \/>\r\ngoto :EOF<br \/>\r\n<br \/>\r\n:PostCheckDrives<br \/>\r\n<br \/>\r\necho ###################################################<br \/>\r\necho.<br \/>\r\n<br \/>\r\n:: Make the hard drive selection:<br \/>\r\nchoice \/c:0123456789 \/n Please select a hard drive number [0-9]:<br \/>\r\nset HDNumber=%ErrorLevel%<br \/>\r\n:: The CHOICE command sets ErrorLevel to the 1-based offset of the key pressed (based on the<br \/>\r\n:: characters \"0123456789\" shown). Since hard drives are 0-based, we need to subtract 1 to adjust:<br \/>\r\nset \/a HDNumber-=1<br \/>\r\n<br \/>\r\n:: Verify the hard drive selection:<br \/>\r\necho.<br \/>\r\necho You selected hard drive number %HDNumber%.<br \/>\r\necho.<br \/>\r\nchoice \/c:YN \/n Is that hard drive number correct [YN]?<br \/>\r\nif ErrorLevel 2 (<br \/>\r\n\u00a0\u00a0 cls<br \/>\r\n\u00a0\u00a0 echo.<br \/>\r\n\u00a0\u00a0 echo No action has been taken.<br \/>\r\n\u00a0\u00a0 echo.<br \/>\r\n\u00a0\u00a0 pause<br \/>\r\n\u00a0\u00a0 goto :EOF\u00a0\u00a0\u00a0 )<br \/>\r\n<br \/>\r\n::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::<br \/>\r\n:: Put your own code below here, doing whatever desired with the selected hard drive<br \/>\r\n:: number, which will be in the variable HDNumber. The ECHO line below is just an example.<br \/>\r\n::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::<br \/>\r\n<br \/>\r\ncls &amp; echo. &amp; echo You selected hard drive number %HDNumber%. &amp; echo.<br \/>\r\n<br \/>\r\n:: End of script<br \/>\r\n<br \/>\r\n<\/p>","protected":false},"excerpt":{"rendered":"<p>The Windows 2000+ command script shown below uses the TeraByte Unlimited EMBR_NT.EXE utility to (in effect) present a hard drive selection menu. Such a menu could be used for any purpose where a Windows command script is being run and a hard drive number needs to be selected.\u00a0 For example, after some customization, the script [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"lsvr_kba_cat":[1782],"lsvr_kba_tag":[2127,2147,2145,2144,2146],"class_list":["post-335","lsvr_kba","type-lsvr_kba","status-publish","hentry","lsvr_kba_cat-nt-2k-xp-2003","lsvr_kba_tag-windows","lsvr_kba_tag-windows-2003","lsvr_kba_tag-windows-2k","lsvr_kba_tag-windows-nt","lsvr_kba_tag-windows-xp"],"_links":{"self":[{"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/lsvr_kba\/335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/lsvr_kba"}],"about":[{"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/types\/lsvr_kba"}],"author":[{"embeddable":true,"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/comments?post=335"}],"version-history":[{"count":2,"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/lsvr_kba\/335\/revisions"}],"predecessor-version":[{"id":6638,"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/lsvr_kba\/335\/revisions\/6638"}],"wp:attachment":[{"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/media?parent=335"}],"wp:term":[{"taxonomy":"lsvr_kba_cat","embeddable":true,"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/lsvr_kba_cat?post=335"},{"taxonomy":"lsvr_kba_tag","embeddable":true,"href":"https:\/\/www.terabyteunlimited.com\/kb\/wp-json\/wp\/v2\/lsvr_kba_tag?post=335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}