codeblue Posted January 10, 2006 Posted January 10, 2006 I know this can be done in a Batch file to detect the CDROMfor %%i 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 %%i:\WIN51 set CDROM=%%i:, but how can you do it for a USB pen?I have files on my pen that need to be copied to 30 machines. I've created a Xcopy batch file:xcopy /y /q "y:\TEST_ONE" "v:\"But where Y: is might be V: on another machine, so i need the Batch file to look for the pen.Is this possible?Did i explaine it right I dont think i posted this in the correct pace?
Synapse Posted January 10, 2006 Posted January 10, 2006 hmm not sure about this, do autorun.inf files work on pen drives? maybe you could make the autorun run a batch file that does the xcopy.
pawls Posted January 10, 2006 Posted January 10, 2006 (edited) You could create a folder named 'USB' on the pendrive and then use this code to detect on wich drive it resides.FOR %%i 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 %%i:\USB set USB=%%i:Now,%USB% = pendrive:\ Edited January 11, 2006 by pawls
gunsmokingman Posted January 10, 2006 Posted January 10, 2006 (edited) I do not know if this will work since I do not have a pen drive.This is a VBS that uses the FileScriptingObject to list the drivesSave As Whatever.VBSThis color text are for either the file or folder you want copy remove all 4 of these '''' to make active. These check to see if they existsThis color text is where you add your own to go locations and file or folder for targetExample Where the file or folder goes toEndLoc = "C:\SOMEFOLDER\NEXTFOLDER This is for the drive letterExample File Target = "SOMEFILE.EXE" In the script this tranlates to Drv & "\SOMEFILE.EXE" Example Folder Target = "\FOLDER_001\FOLDER_002" In the script this tranlates to Drv & "\FOLDER_001\FOLDER_002" Const OverwriteExisting = True '''' PREVENTS THE FILE OR FOLDER WAS THERE DIALOGDim Drv, EndLoc, Fso, Target: Set Fso = CreateObject("Scripting.FileSystemObject")Set colDrives = Fso.DrivesEndLoc = (FILL_IN_WHERE_IT_GOES)Target = (THE_FOLDER_OR_FILE) For Each objDrive in colDrivesIf objDrive.IsReady = True Then Drv = objDrive.DriveLetter & ":\"'''' If File'''' If Fso.FileExists(Drv & Target) : Then : Fso.CopyFile(Drv & Target),(EndLoc),OverwriteExisting : End If '''' If Folder''''If Fso.FileExists(Drv & Target) : Then : Fso.CopyFile(Drv & Target),(EndLoc),OverwriteExisting : End If End If Next Edited January 10, 2006 by gunsmokingman
FrankE9999 Posted January 10, 2006 Posted January 10, 2006 Not sure where you have the batch file stored. If you put it on the USB drive you can use %~d0 to get the drive letter or %~dp0 to get the full path to the batch file.Example batch file D:\Temp\t.bat@echo offecho %~dp0echo %~d0OutputD:\Temp\D:
codeblue Posted January 10, 2006 Author Posted January 10, 2006 (edited) @PawlsIf only it was that simple Didnt work@gunsmokingmanThanks for your suggestion but a .vbs script will be picked up as a virus or dangerous file. Would rather use Batch files if possible.This is my current baych file. Y=pendrivecls@echo offTitle Coping Files to uesrprofile and Shortcuts to DesktopMODE CON COLS=80 LINES=30color 4fxcopy /y "Y:\LessonMaterial\TrainingData\Shortcuts\*.*" "%userprofile%\desktop"xcopy /e /k /i /c /r /y "Y:\LessonMaterial" "%userprofile%\Personal\"ECHO Shutting down computer in 5 secondsShutdown -s /f /t 5 /c "One step to gooooooooo............"@FrankE9999Could you incorpreate your suggestion into my Batch file, not to sure what your getting at. Thanks Edited January 10, 2006 by codeblue
InTheWayBoy Posted January 11, 2006 Posted January 11, 2006 You could use the ".\" to inform the script to start in the same place as the script...so for your script it would be something like this:cls@echo offTitle Coping Files to uesrprofile and Shortcuts to DesktopMODE CON COLS=80 LINES=30color 4fxcopy /y ".\LessonMaterial\TrainingData\Shortcuts\*.*" "%userprofile%\desktop"xcopy /e /k /i /c /r /y ".\LessonMaterial" "%userprofile%\Personal\"ECHO Shutting down computer in 5 secondsShutdown -s /f /t 5 /c "One step to gooooooooo............"That's assuming that both the script and the LessonMaterial folder are in the root of the drive...or parallel to each other. Remember, this uses the place the script runs from as it's base, so if it's running from the local temp dir then it's not gonna do you any good. But if you are running the script straight from the drive then it should work. Couple this with the autorun idea mentioned earlier and those 30 will fly by.
codeblue Posted January 11, 2006 Author Posted January 11, 2006 (edited) @Bi0haZarDSo on the PEN i need an autorun.inf file containing the following:[autorun]open=Training data.cmdTrainingData in the name of the batch file@InthewayboyThanks, ".\" works Although not quite what i was looking for it works and i can move on !!Anyone know how to add this to my script?:Do you want to shutdown the PC? Y/NIf Y Shutdown (goto?)If N exit Edited January 11, 2006 by codeblue
boggen Posted January 11, 2006 Posted January 11, 2006 choice (forgot command reference) check ryanrvm bts.....cmd file it has a couple choice commands sets in it.
codeblue Posted January 11, 2006 Author Posted January 11, 2006 (edited) bts?I have this:set answer=yset /p answer=Do you want to Shutdown PC? if not "%answer:~0,1%"=="y" goto :ENDECHO Shutting down computer in 5 secondsShutdown -s /f /t 5 /c "One step to gooooooooo............":ENDBut the user needs to hit enter after 'y'. Not a problem, but not ideal.Another minor issue is that the Dos screen isnt the active screen, the user needs to click in it to enter 'Y'. Is there a command to force the dos screen to become the active screen? Edited January 11, 2006 by codeblue
pawls Posted January 11, 2006 Posted January 11, 2006 Dunno why I slipped in a CLS up there. Anyhow this works for me:FOR %%i 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 %%i:\USB set USB=%%i:CLS%USB%DIRMakes %USB% the driveletter of the usb-drive.
ivwolferen Posted January 11, 2006 Posted January 11, 2006 Hi,If you want to accomplish an automatic XCOPY action after inserting the USB pendrive without user interference, forget it.Autorun files will not work on USB pendrives. I have been trying this for a while, and a long google surch revealed a Microsoft explanation that USB pendrives are treated different in windows than CD-ROM's.A way to do this is to have a batch file on the host machines that will look for a specific map on the pendrive. Example: Create a folder named: 012345678On the host machine , start a batch task that will look on d: e: f: .... z: for a folder 12345678 using errorcodes.When the folder is found, you have your drive and XOPY the files you need.It can be a very simple batch file that you can run in windows task scheduler every 10 minutes (or less if it is a very regular task).Use CMDow.exe to hide this batch file from the users working behind the machines.Succes!Ivo
Synapse Posted January 11, 2006 Posted January 11, 2006 (edited) @codebluei tried the autorun.inf last night on my 128mb pendrive, seems that only the icon= line works. could'nt get mine to autorun without some sort of 3rd party program. and i haven't tried any of the scripts mentioned in this post.although.., i was able to get the explorer.exe shell to show up with the contents of the drive by using:[autorun]icon=setup.exe*was using the setup.exe that comes with the windows xp cd* but still no autorun.just kinda curious, but wouldn't this be easier with a cd... sure you can't use it again, unless its a cd-rw.. but at least with that you can setup a autorun... Edited January 11, 2006 by Bi0haZarD
FrankE9999 Posted January 11, 2006 Posted January 11, 2006 @PawlsIf only it was that simple Didnt work@gunsmokingmanThanks for your suggestion but a .vbs script will be picked up as a virus or dangerous file. Would rather use Batch files if possible.This is my current baych file. Y=pendrivecls@echo offTitle Coping Files to uesrprofile and Shortcuts to DesktopMODE CON COLS=80 LINES=30color 4fxcopy /y "Y:\LessonMaterial\TrainingData\Shortcuts\*.*" "%userprofile%\desktop"xcopy /e /k /i /c /r /y "Y:\LessonMaterial" "%userprofile%\Personal\"ECHO Shutting down computer in 5 secondsShutdown -s /f /t 5 /c "One step to gooooooooo............"@FrankE9999Could you incorpreate your suggestion into my Batch file, not to sure what your getting at. ThanksIf you are running Windows XP or 2000 and the script you are trying to run is on the key. %~d0 expands to the drive letter of the script which will be the same as the drive letter of the key since the batch file you are running is on the key.xcopy /y "%~d0\LessonMaterial\TrainingData\Shortcuts\*.*" "%userprofile%\desktop"xcopy /e /k /i /c /r /y "%~d0\LessonMaterial" "%userprofile%\Personal\"
codeblue Posted January 13, 2006 Author Posted January 13, 2006 All sorted, thanks to all for your advise. Made 3 cd that autoran, but also used the pen but without autorun
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now