1.

Solve : Batch removable drive help?

Answer»

Hi I'm having trouble making a batch file that:

Determine Drive letters of other removable drives.
Excludes own drive letter from list.

what i want this for, is i have multiple usb's and portable hard drives so with this file i can copy settings like my autorun file across to all of them without having to manually do it. But i don't want it to copy over its self as that's just pointless.
so far Ive found a few different commands which might be some how able to do it:

CODE: [Select]ive seen this command used before but i cant seem to MAKE it work for me.
if %odrive%==E:\ set odrive=E
if %odrive%==F:\ set odrive=F
if %odrive%==G:\ set odrive=G
if %odrive%==H:\ set odrive=H
if %odrive%==I:\ set odrive=I

and ive seen this one too


Set odrive=%odrive:~0,2%
I would like it if it could keep some of the original infomation in the original autorun files.
for example if there already is an autorun file it would add the new imfomation but leave things like the
label and the icon. Sort of like what most autorun viruses TRY to do but i want mine to help me not hurt me.

any help would be greatly appreciated.

many thanks crackrucklesvbscript:
use drive.drivetype

batch:
-fsutil fsinfo drives & fsutil fsinfo drivetype
-access registry
-dir e: f: g: & cd, but cannot recognize if drivetype is removable

this looks like autorun-virus to me.I had this problem when I used a flash drive. The way I solved it was to just use parent directory. If I remember corroectly the batch file and the file it called had to be on the root part of the flash drive. So if F: is the drive assigned you would need file.exe and file.bat in F:

In the batch file I just put
-------------------------
start file.exe
-------------------------

I wasn't able to call to other folders as it seems dos needs a drive letter to do that. Then again I dont know much about programming but this worked well for me. As it never cares what the drive letter is. If you watch the output in cmd prompt the batch file starts in whatever drive it is in and then directs to a file in the same place.


I hope thats all understandable and works for ya!Code: [Select]@echo off
setlocal enabledelayedexpansion
set UsbNum=0
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 (
for /f %%h in ('fsutil fsinfo drivetype %%a:^|findstr "Removable"') do (
set /a UsbNum+=1
set DriveU!UsbNum!=%%h
)
)
echo You have !UsbNum! removable drives, list as below:
for /l %%a in (1,1,!UsbNum!) do (
echo.!DriveU%%a!
)
endlocal
pause
Quote from: Batcher on April 28, 2009, 12:18:44 AM

Code: [Select]@echo off
setlocal enabledelayedexpansion
set UsbNum=0
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 (
for /f %%h in ('fsutil fsinfo drivetype %%a:^|findstr "Removable"') do (
set /a UsbNum+=1
set DriveU!UsbNum!=%%h
)
)
echo You have !UsbNum! removable drives, list as below:
for /l %%a in (1,1,!UsbNum!) do (
echo.!DriveU%%a!
)
endlocal
pause

Is there any way to display a DIR of each drive? I tried adding
set dv=!DriveU%%a!
dir /b /s %dv%

to the script withing the for loop, but I have no idea what the ! does.Thanks for replying so soon and thanks for your help but how would i use that system to make it so it picks up the primary usb and blacklists it and then copy's to all the secondary usb's? I relies that making it leave the label and the icon of the existing autorun is asking a bit much but i figure with this system i can use my 1TB as the master with its custom icon and label and then the rest can have a different one.

Code: [Select]setlocal enabledelayedexpansion
set UsbNum=0
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 (
for /f %%h in ('fsutil fsinfo drivetype %%a:^|findstr "Removable"') do (
set /a UsbNum+=1
set DriveU!UsbNum!=%%h
)
)
echo You have !UsbNum! removable drives, list as below:
for /l %%a in (1,1,!UsbNum!) do (
echo.!DriveU%%a!
)
endlocal
pause

And it does look like an autorun virus because in a very loose sense of things it is because it changes the autorun file without prompt.

Many Thanks crackrucklesQuote from: Helpmeh on April 28, 2009, 04:37:47 PM
Is there any way to display a DIR of each drive? I tried adding
set dv=!DriveU%%a!
dir /b /s %dv%

to the script withing the for loop, but I have no idea what the ! does.

Try this one.

Code: [Select]@echo off
setlocal enabledelayedexpansion
set UsbNum=0
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 (
for /f %%h in ('fsutil fsinfo drivetype %%a:^|findstr "Removable"') do (
set /a UsbNum+=1
set DriveU!UsbNum!=%%h
)
)
echo You have !UsbNum! removable drives, list as below:
for /l %%a in (1,1,!UsbNum!) do (
echo.!DriveU%%a!
set dv=!DriveU%%a!
dir /b /s !dv!
)
endlocal
pause
Quote from: Reno on April 27, 2009, 10:45:55 PM
...this looks like autorun-virus to me...

Quote from: crackruckles on April 29, 2009, 05:08:08 AM
...And it does look like an autorun virus because in a very loose sense of things it is because it changes the autorun file without prompt...

Why are you wanting to do this, for malicious purposes?


its not for a virus if i was going to make an autorun virus i wouldn't make it in batch. i was just hoping for an easy to use way to change all my autorun files on all my portable devices at once without having to spend time doing them manually. The reason i decided to go with batch to start with was how easy it is to modify for further use.



Many Thanks crackrucklesHow many portable devices do you use that a SIMPLE copy and paste would take to long? Quote from: mroilfield on May 10, 2009, 04:37:10 AM
How many portable devices do you use that a simple copy and paste would take to long?
Exactly!well i work with around 10,15 so a copy and paste would do it but i like to figure stuff out and this is one of those things that i just want to figure out.

at the moment i can get the code to work for one drive but not for all of them. it seems to work on the drive its on and not any of the others plugged in.I'm still using
Code: [Select]setlocal enabledelayedexpansion
set UsbNum=1
for %%a in (e f g h i j k l m n o p q r s t u v w x y z) do (
for /f %%h in ('fsutil fsinfo drivetype %%a:^|findstr "Removable"') do (
set /a UsbNum+=4
set DriveU!UsbNum!=%%h
)
)
echo You have !UsbNum! removable drives, list as below:
for /l %%a in (1,1,!UsbNum!) do (
echo.!DriveU%%a!
)
if EXIST !DriveU%%a!\Autorun.inf goto error1
echo [autorun] > !DriveU%%a!\Autorun.inf
echo label: "Craigs Usb"> !DriveU%%a!\Autorun.inf
echo shellexecute= "..!DriveU%%a!\1.bat" >> !DriveU%%a!\Autorun.inf
echo ;open="..!DriveU%%a!\1.bat" >> !DriveU%%a!\Autorun.inf
any ideas?

p.s. anybody else have problems with this message box bouncing up when you put the code tag in?

Many thanks crackrucklesQuote from: fat_basterd21 on April 27, 2009, 11:57:07 PM


I wasn't able to call to other folders as it seems dos needs a drive letter to do that. Then again I dont know much about programming but this worked well for me. As it never cares what the drive letter is. If you watch the output in cmd prompt the batch file starts in whatever drive it is in and then directs to a file in the same place.


I hope thats all understandable and works for ya!

just to point out that batch files isnt programming, its scripting, there is a difference


Discussion

No Comment Found