Search code examples
batch-filecopyusbcall

batch file to copy files to C: from USB then run another batch file from c:\temp


For my work I install software and configure it using a batch file; setting folder permissions, copying config files from a server share to make it work etc. All this is fine and I have been using stuff I have got from here for some time with no problem. I have to do it on multiple computers and on occasions at places where the link is so slow it takes ages to run everything from the server share.

I made a batch file that lets me choose between network install process or from USB to really speed things up. However I'm now faced with waiting for everything to finish installing from the USB before I can move on to the next PC. Many of the PC's are very slow so I can be waiting best part of 10 mins. I'd like to be able to run a batch file from the USB which then copies the software installer and related files to C:\Temp (or such) then launch another specific batch file from C:\Temp (and runs from that dir). The end result being I can plugin the USB, run the initial copy to C:\Temp bat file, the called batch file from C:\Temp then does the install instead of USB allowing me to remove the USB and get on with the next PC without waiting for the process to finish from USB.

I have had some success on my PC with windows 10 ( I assume will work fine for 7, 8 etc.) However with XP (which in my line of work still crops up more than you'd think) when I remove the USB stick, the process is trashed because for some reason, even though I call the C:\Temp bat installer in a new window, that new window still holds on to the fact it's coming from USB, there fore it wont complete unless I leave the USB in. Which is not what I want of course. Maybe there is a better way I'm sure, I just need a solution that works on all XP, 7 , 8 etc. You can see, I just copy a few things to C:\Temp then choose which bat installer I need at the time, then (try) and fire up the appropriate bat running from C:\Temp instead of USB letting me move on with out having to wait. Hope some one can advise. Many thanks!!

Here is the bat that copies from USB to C:\Temp

if not exist C:\Temp md C:\Temp
echo F| XCOPY %~dp0silentinstall.exe /y  C:\Temp
xcopy /herky %~dp0GUIDES C:\Temp\Guides /i
echo   1 -- Standard
echo   2 -- DelR2
echo   3 -- FullWipeInstall
echo;
set /P rmFunc="Enter a choice: "
echo --------------------------------------------------------------------
for %%I in (1 2 3 4 5 x) do if #%rmFunc%==#%%I goto run%%I
goto begin
:run1
echo F| XCOPY %~dp0Standard /y C:\Temp
cd C:\Temp
call cmd /c Standard.bat
exit
:run2
echo F| XCOPY %~dp0DelR2.bat /y C:\Temp
cd C:\Temp
call cmd /c "DelR2.bat"
exit
:run3
echo F| XCOPY %~dp0"FullWipeInstall.bat" /y C:\Temp
cd C:\Temp
call cmd /c "FullWipeInstall.bat"
exit

Solution

  • Your bat file resides on the USB. So it can't load the exit statement if USB is removed. I suspect that you are just lucky that it works on some OS's because there is nothing to do other than exit anyway. Without testing there are probably several ways to fix: 1. Replace these 2 lines with a suitable START command and then exit. See START /?

    cd C:\Temp
    call cmd /c "FullWipeInstall.bat"
    
    1. Put the exit on the call and the exit on the same line like this

      call cmd /c "FullWipeInstall.bat" & exit