Bat file help If exist...
#1
Posted 10 April 2008 - 12:53 PM
if exist D:\Install set drive=D
if exist E:\Install set drive=E
if exist F:\Install set drive=F
Simple 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?
#2
Posted 11 April 2008 - 10:21 AM
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").Drives
For Each drive In colDrives
If drive.isReady Then
If StrComp(drive.VolumeName, strVolName, 1) = 0 Then
WScript.echo drive.VolumeName & " is drive letter " & drive.Path
End If
End If
Next
Change 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.
#3
Posted 11 April 2008 - 08:36 PM
Save As Usb_DriveCheck.cmd
Quote
@Echo Off
CLS
Color F9
Mode 65,5
Title Check For USB Drive
Echo.
Echo Processing the USB Drive Letter
set ChkUsb=%SystemDrive%\ChkUsb.vbs
Echo 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 Here
Echo 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.cmd
Set %USB%=
Del %ChkUsb%
Del %SystemDrive%\ChkUsb.cmd
Echo %USB%
Pause
del %SystemDrive%\ChkUsb.cmd
#4
Posted 14 April 2008 - 01:14 PM
#5
Posted 15 April 2008 - 09:58 AM
I am assuming that you have the fsutil command available.
This will skip checking against CD-ROM drives.
@echo off
for /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=%1
goto :eof
:skipme
endlocal
echo Performing task on %drive%
You may need to change the statement in the doStuff routine to check for your folder/file.
#6
Posted 15 April 2008 - 01:45 PM
I made a few slight changes to fit my bat file but it was exactly what I was asking for. Thanks again!
#7
Posted 15 April 2008 - 03:44 PM
Since the task is not to ignore the CD-ROM but to find the USB Drive, then this should do fine:
@Echo off&Setlocal enableextensions
For /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%
#8
Posted 16 April 2008 - 11:58 AM
Can anyone explain how Scr1ptW1zard's scrip works? Mainly these two lines.
set chkdrive=!chkdrive:Drives:=!
set chkdrive=!chkdrive: =!
What are the "!" used for?
#9
Posted 16 April 2008 - 01:48 PM
#10
Posted 16 April 2008 - 03:08 PM
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 . . .”
#11
Posted 16 April 2008 - 03:35 PM
Attached File(s)
-
GetUsbKey.zip (320bytes)
Number of downloads: 13
#12
Posted 16 April 2008 - 08:20 PM
'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 I
like 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 am
performing as described above. 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". 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 Drive
My script is checking all drives that are NOT a CD-ROM drive, therefore you are
receiving the desired result.
#13
Posted 16 April 2008 - 10:24 PM
Smiley357, on Apr 16 2008, 06:58 PM, said:
Scr1ptW1zard, on Apr 17 2008, 03:20 AM, said:
It is your Removable Drive which therefore isn't working properly, not my code! which brings me full circle back to this!
Yzöwl, on Apr 11 2008, 05:21 PM, said:
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.
#14
Posted 17 April 2008 - 07:56 AM
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
This post has been edited by Smiley357: 17 April 2008 - 07:58 AM
- ← Existing script, help required
- Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
- Modifying GLD (Glide) files →



Help
Back to top









