Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Dos_Probie
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
#1
Post
by Dos_Probie » 14 Oct 2012 08:03
Been using the following codes to detect then run off usb and then one for dvd, would like to combine both to a If Else goto
USB or DVD so if usb pendrive is present it would go to that or if a Disc in dvd is present it would go there..
Thanks for the help, Dos_Probie
Code: Select all
:: USB_Scan
for %%a in (C D E F G H) do (
fsutil.exe fsinfo drivetype %%a:|find "Removable">nul&&set usb=%%a&&goto:%%a
)
:: DVD_Scan
for %%b in (C D E F G H) do (
fsutil.exe fsinfo drivetype %%b:|find "CD-ROM">nul&&set dvd=%%b&&goto:%%b
)
Last edited by
Dos_Probie on 18 Oct 2012 20:30, edited 1 time in total.
-
abc0502
- Posts: 1007
- Joined: 26 Oct 2011 22:38
- Location: Egypt
#2
Post
by abc0502 » 14 Oct 2012 10:19
Do you run the code from the DVD ?
Edit:Try writing it that way
Code: Select all
@echo off
For %%a in (C D E F G H) Do (
For /F "tokens=3 delims= " %%b in ('FSUTIL.EXE fsinfo drivetype "%%a:"') Do (
IF "%%b" == "Removable" ( Echo It's a USB )
IF "%%b" == "CD-ROM" ( Echo It's a CD-Rom )
IF "%%b" == "Fixed" ( Echo It's a HDD Partion )
)
)
pause
Last edited by
abc0502 on 14 Oct 2012 10:31, edited 3 times in total.
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#3
Post
by foxidrive » 14 Oct 2012 10:22
Another question: can you put a file in the root of the USB and DVD?
Which one do you want to use if both a USB and DVD exist?
-
abc0502
- Posts: 1007
- Joined: 26 Oct 2011 22:38
- Location: Egypt
#4
Post
by abc0502 » 14 Oct 2012 10:42
Another question: can you put a file in the root of the USB and DVD?
I use the USB serial number, you can get it using the vol command
and This is the code to match the serial number
For %%A in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) Do (
if exist "%%A:\" (for /f "tokens=5 delims= " %%B in ('Vol %%A:') Do if %%B==C073-25E8 set drv=%%A)
)
but i don't know if it will work for the DVD, each CD/DVD disk has a different serial number

-
Dos_Probie
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
#5
Post
by Dos_Probie » 14 Oct 2012 16:50
Which one do you want to use if both a USB and DVD exist?
If both exist I would rather default to the USB since it would be faster that using
the DVD, I just want the option to search for both and whichever one exist as in a usb pendrive
is plugged in or a dvd disc is in try then go to usb as the 1st option then I can add my
code for my batch from there..Hope this explains its better
-
Dos_Probie
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
#6
Post
by Dos_Probie » 14 Oct 2012 17:11
I thought about the serial, which I can get from the registry but it changes for each usb drive so that
was out, but if I can somehow combine my find CD-ROM and find Removable then it would cover both ..
I updated my code and this is reading both for now..
Code: Select all
:: DVD_Scan
for %%b in (C D E F G H) do (
fsutil.exe fsinfo drivetype %%a:|find "CD-ROM">nul&&set dvd=%%a&&goto:%%a
)
:: USB-Scan
for %%a in (D E F G H) do (
fsutil.exe fsinfo drivetype %%a:|find "Removable">nul&&set usb=%%a&&goto:%%a
)
:e
echo E: is your USB drive..
d:
echo D: is your DVD drive..
pause
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#7
Post
by foxidrive » 14 Oct 2012 23:17
Dos_Probie wrote:Hope this explains its better
And my first question, regarding a specific file in the root?
You can search for the file without any external programs.
Code: Select all
@echo off
set "drv="
for %%a in (c d e f g h) do if exist "%%a:\flagfile.txt" set drv=%%a:&goto :done
:done
if defined drv (
echo found a drive on %drv%
) else (
echo no drive found
)
-
Dos_Probie
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
#8
Post
by Dos_Probie » 15 Oct 2012 07:30
Foxi, I have the bootmgr.efi on both my usb and dvd but when i add to your script
I get 'do' is not recognized as an internal or external command error..

-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#9
Post
by Squashman » 15 Oct 2012 09:14
One extra DO in the code.
IF does not use DO.
-
Dos_Probie
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
#11
Post
by Dos_Probie » 15 Oct 2012 21:57
Ok, Thanks for everyone's help I got this working now, This is my completed batch..Tested with USB and DVD. Life Is Good..
Code: Select all
@echo off&color a
title, [ + OFFLINE INSTALL OF WINOWS 8 - NET 3.5 FRAMEWORK + ]
::NOTE: INSTALLS .NET 3.5 FRAMWORK FOR WINDOWS 8 FROM INSTALL DISC.
::NetFx35.cmd
:: SCAN_ACTIVE DRIVES
set "drv="
for %%a in (D E F G H I) do if exist "%%a:\bootmgr.efi" set drv=%%a:&goto :Install
:Install
if defined drv (
echo == Installing NET 3.5 From Drive %drv%
Dism /online /enable-feature /featurename:NetFx3 /All /Source:%drv%\sources\sxs /LimitAccess
echo.&echo.
cls
echo * DONE *
echo.&echo.
echo == Press any [KEY] to Close This Screen. &pause>nul
) else (
:: NO_DRIVE
echo == No Active Drive Found!..Insert DVD or USB then Start Over. &pause>nul
echo.
)
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#13
Post
by foxidrive » 16 Oct 2012 05:59
.net V4 breaks media center PCs but MS still feeds it to them, even though it's not one of the supported models.
Anyway, I just wanted to say that each .net framework release services different programs so V4 doesn't support all the programs that were written for 3.5, 3.0, 2, 1, 1.1 and you need them all, if you use programs written for them.
I've had so many headaches with .net framework and having to uninstall and reinstall the lot because the latest .net security update refuses to load for one version or another.
-
Squashman
- Expert
- Posts: 4488
- Joined: 23 Dec 2011 13:59
#14
Post
by Squashman » 16 Oct 2012 06:27
foxidrive wrote:.net V4 breaks media center PCs but MS still feeds it to them, even though it's not one of the supported models.
Anyway, I just wanted to say that each .net framework release services different programs so V4 doesn't support all the programs that were written for 3.5, 3.0, 2, 1, 1.1 and you need them all, if you use programs written for them.
I've had so many headaches with .net framework and having to uninstall and reinstall the lot because the latest .net security update refuses to load for one version or another.
I just had that headache last week as well.
-
Dos_Probie
- Posts: 233
- Joined: 21 Nov 2010 08:07
- Location: At My Computer
#15
Post
by Dos_Probie » 16 Oct 2012 09:43
Actually up to 4.5 now , Windows 8 includes .Net 4.5 by default but not .NET 3.5, which means that most apps designed for Win7 won't work til you add 3.5, Microsoft decided in there great wisdom not to pre-install .NET 3.5 but leave it up to the enduser to deal with it either via Windows update (274MB) Slowww..or doing like I am doing by way of a offline install from the Sources folder. Which now only takes me about 50 seconds off of a 3.0 USB.
