jkdesigns
jkdesigns

Reputation: 41

call a vbs file in a removable drive to run

I need a little explanation on specifying path to mounted removable disk. My batch code...

wmic LOGICALDISK where driveType=2 get deviceID > "C:\Windows\Temp\wmic.txt" 
cls
for /f "skip=1" %%b IN ('type C:\Windows\Temp\wmic.txt') DO (xcopy JKDClean.bat %%b /Y)
for /f "skip=1" %%b IN ('type C:\Windows\Temp\wmic.txt') DO (xcopy run.vbs %%b /Y)
echo -----
echo Cleaning removable disk
for /f "skip=1" %%b IN ('type C:\Windows\Temp\wmic.txt') DO (wscript %%b\run.vbs)
TIMEOUT /T 10 /NOBREAK
echo DONE!!!
echo -----
for /f "skip=1" %%b IN ('type C:\Windows\Temp\wmic.txt') DO (del /s /q /f %%b\*.inf)
Del C:\Windows\Temp\wmic.txt
echo -----
echo DONE!!!
pause

In line 4 "xcopy JKDClean.bat %%b" path is working better. But I couldn't run that vbs file, "wscript %%b\run.vbs". I need that vbs file to be run eithin the removable drive. How specify path for current removable disk???

Upvotes: 3

Views: 135

Answers (1)

Compo
Compo

Reputation: 38623

why so many for loops:

@Echo Off
For /F "Skip=1" %%I In ('WMIC LogicalDisk Where DriveType^=2 Get DeviceID'
    ) Do (For %%J In (%%I) Do (Echo=Copy file.ext %%I & Echo=Copy file2.ext %%I
    Echo=run %%I\file2.ext & Echo=Del/S/Q %%I\*.ext2))
Echo( Done & Timeout -1

Note you do realise that some drives used internally can be seen as Removable, your code isn't just catering for USB Thumb/Flash drives!

Upvotes: 1

Related Questions