Smiley357 Posted April 10, 2008 Share Posted April 10, 2008 I have a Bat file that checks for the usb drive. It was working fine for a long time but now it’s doing something different. Here is the code:if exist D:\Install set drive=Dif exist E:\Install set drive=Eif exist F:\Install set drive=FSimple but now when it comes to the CD-rom drive it sends a prompt saying to insert cd and click retry, cancel, or continue. If there is a CD in the CD-rom there is no issue no prompt. But why is there a prompt now and how to you stop the prompt? Link to comment Share on other sites More sharing options...
Yzöwl Posted April 11, 2008 Share Posted April 11, 2008 I'd like to provide a comment rather than a direct solution on this occasion.I'm astonished how often this kind of question arises, I could understand to a degree when using CD-ROMs but not with removable drives.All you need to do is create a Volume/Label Name for your removable drives, any script can then quickly check for that name as opposed to using a unique file/folder placed on its root.Just a quick VBS example, it doesn't directly answer your question but could if required be altered to run from a batch file:strVolName = "mythumb"Set colDrives = CreateObject("Scripting.FileSystemObject").DrivesFor Each drive In colDrivesIf drive.isReady Then If StrComp(drive.VolumeName, strVolName, 1) = 0 Then WScript.echo drive.VolumeName & " is drive letter " & drive.Path End IfEnd IfNextChange the content of the quotes on the first line (case insensitive) to your drive volume name to test it!The noticeable thing for your particular problem is that it checks to see if the drive is ready first, thus negating the not ready messages your currently getting. Link to comment Share on other sites More sharing options...
gunsmokingman Posted April 12, 2008 Share Posted April 12, 2008 Here a cmd file that produces a VBS script that is similar to what Yzöwl posted works the same way.Save As Usb_DriveCheck.cmd@Echo OffCLSColor F9Mode 65,5Title Check For USB DriveEcho. Echo Processing the USB Drive Letterset ChkUsb=%SystemDrive%\ChkUsb.vbsEcho Dim Drv, ChkFile, strFile, StrD, TS, Fso : Set Fso = CreateObject("Scripting.FileSystemObject") > %ChkUsb%Echo Set Drv = Fso.Drives >> %ChkUsb% :: Place The Name Of The File HereEcho ChkFile = "\i386\ZONEOC.DL_" >> %ChkUsb% Echo strFile = Fso.GetFolder(Fso.GetParentFolderName(WScript.ScriptFullName)) ^& "\ChkUsb.cmd" >> %ChkUsb% Echo For Each StrD In Drv >> %ChkUsb% Echo If StrD.IsReady Then >> %ChkUsb%Echo If Fso.FileExists(StrD ^& ChkFile) Then >> %ChkUsb%Echo Set TS = Fso.CreateTextFile(strFile) >> %ChkUsb%Echo Ts.WriteLine "Set USB=" ^& StrD ^& "\" : TS.Close >> %ChkUsb%Echo Else >> %ChkUsb% Echo Set TS = Fso.CreateTextFile(strFile) >> %ChkUsb%Echo Ts.WriteLine "Set USB=Wrong_USB_Drive" : TS.Close >> %ChkUsb%Echo End If >> %ChkUsb%Echo End If >> %ChkUsb%Echo Next >> %ChkUsb%Start /w %ChkUsb%Call %SystemDrive%\ChkUsb.cmdSet %USB%=Del %ChkUsb%Del %SystemDrive%\ChkUsb.cmdEcho %USB%Pause del %SystemDrive%\ChkUsb.cmd Link to comment Share on other sites More sharing options...
Smiley357 Posted April 14, 2008 Author Share Posted April 14, 2008 That would be fine if I use the same USB drive. This will need to be more portable then just this one drive. Meaning that the bat file can find any USB drive that has the files. I’m still puzzled why it is now all of a sudden sending a prompt when there is no CD in the CD-ROM? Link to comment Share on other sites More sharing options...
Scr1ptW1zard Posted April 15, 2008 Share Posted April 15, 2008 Perhaps this will work for you.I am assuming that you have the fsutil command available.This will skip checking against CD-ROM drives.@echo offfor /f "tokens=*" %%a in ('fsutil fsinfo drives^|more') do ( setlocal enabledelayedexpansion set chkdrive=%%a set chkdrive=!chkdrive:Drives:=! set chkdrive=!chkdrive: =! fsutil fsinfo drivetype !chkdrive!|find /i "CD-ROM">nul if errorlevel 1 call :doStuff !chkdrive!)goto skipme:doStuff endlocal if exist %1Install set drive=%1goto :eof:skipmeendlocalecho Performing task on %drive%You may need to change the statement in the doStuff routine to check for your folder/file. Link to comment Share on other sites More sharing options...
Smiley357 Posted April 15, 2008 Author Share Posted April 15, 2008 This worked perfectly. Thanks for everyone’s help! I made a few slight changes to fit my bat file but it was exactly what I was asking for. Thanks again! Link to comment Share on other sites More sharing options...
Yzöwl Posted April 15, 2008 Share Posted April 15, 2008 If you're happy to use FSUTIL which requires Admin status to run, then you could improve on Scr1ptW1zard's example still further.Since the task is not to ignore the CD-ROM but to find the USB Drive, then this should do fine:@Echo off&Setlocal enableextensionsFor /f %%# In ('Mountvol^|Findstr [d-z]:\\') Do ( Fsutil fsinfo drivetype %%#|Find "Removable Drive">Nul&&( If Exist %%#Install Set "ThumbDrv=%%~d#"))If defined ThumbDrv Echo:%%ThumbDrv%%=%ThumbDrv% Link to comment Share on other sites More sharing options...
Smiley357 Posted April 16, 2008 Author Share Posted April 16, 2008 Sorry Yzowl your code didn’t work. Nothing was returned. Can anyone explain how Scr1ptW1zard's scrip works? Mainly these two lines. set chkdrive=!chkdrive:Drives:=! set chkdrive=!chkdrive: =!What are the "!" used for? Link to comment Share on other sites More sharing options...
Yzöwl Posted April 16, 2008 Share Posted April 16, 2008 Sorry Yzowl your code didn’t work. Nothing was returned.Of course my code works!It has worked flawlessly on hundreds of systems for many years now. Link to comment Share on other sites More sharing options...
Smiley357 Posted April 16, 2008 Author Share Posted April 16, 2008 Yzowl:I just copied and pasted your code into a note pad added a pause at the end and saved it as a bat file. Ran it and the only output I got was “Press any key to continue . . .” Link to comment Share on other sites More sharing options...
Yzöwl Posted April 16, 2008 Share Posted April 16, 2008 Try this attached version as copied/pasted by me with your included Pause!GetUsbKey.zip Link to comment Share on other sites More sharing options...
Scr1ptW1zard Posted April 17, 2008 Share Posted April 17, 2008 Here is an explanation to my script:'fsutil fsinfo drives^|more'The output from the above command produces this output (your drive list may vary):Drives: A:\C:\D:\E:\X:\But we only want the drive letters, so I remove the string "Drives:" with set chkdrive=!chkdrive:Drives:=!The above simply replaces the string "Drives:" with "".The statement set chkdrive=!chkdrive: =!Does a similar replacement of the space " ". This is not really needed, but Ilike to be neat. The exclamation marks (!) are required when referencing environment variables(instead of %) while enabledelayedexpansion is set.Yzöwl's script works as well, and actually eliminates the need for what I amperforming as described above. The problem you may be having with his scriptcould be that your USB drive is not recognized as a "Removable Drive". I actuallyhave two USB drives attached to my system, and one is seen as a "Removable Drive"while the other is seen as a "Fixed Drive". To test this, run the following command(replace D:\ with your USB drive):fsutil fsinfo drivetype D:\For Yzöwl's script to work, the above command will need to return:D:\ - Removable DriveMy script is checking all drives that are NOT a CD-ROM drive, therefore you arereceiving the desired result. Link to comment Share on other sites More sharing options...
Yzöwl Posted April 17, 2008 Share Posted April 17, 2008 Nothing was returned.The problem you may be having with his script could be that your USB drive is not recognized as a "Removable Drive". I actually have two USB drives attached to my system, and one is seen as a "Removable Drive" while the other is seen as a "Fixed Drive"It is your Removable Drive which therefore isn't working properly, not my code! which brings me full circle back to this!create a Volume/Label Name for your removable drives, any script can then quickly check for thatYour refusal to do so doesn't really hold water, it's just as quick and simple to do this as to add the install folder in the first place.In any case, if you still wished to continue to just ignore the CD-ROM querying you only need to replace"Removable Drive" with /v "CD-ROM" in my script. Link to comment Share on other sites More sharing options...
Smiley357 Posted April 17, 2008 Author Share Posted April 17, 2008 (edited) Yzowl:Sorry but your code doesn't work at all! LOL j/k You seem to be offended by my statement. I didn't mean to offend anyone. I guess I should have been more specific in my statement. The code didn't work for me would have been a more accurate statement. I tested your code and after replacing "Removable Drive" with /v "CD-ROM" as you stated it worked like a charm. Thanks again for the help.Scr1ptW1zard:Thanks for the script but even more thanks for explaining it. That helped me out the most. It is nice that people are willing to write scripts for others but it's even nicer when they explain how it works. That way others can learn from the script and use it for themselves. Thanks again for everyone's help! :)ly Edited April 17, 2008 by Smiley357 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now