RogueSpear Posted November 1, 2004 Share Posted November 1, 2004 I don't remember who came up with this simple and elegant, yet brilliant piece of batch:set tagfile=\WIN51for %%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:%tagfile%" set CDDRIVE=%%i:but it inspired me to come up with an equivelent in VBscript, as that is my preferred scripting environment. So here it is:Dim strTemp, Drives, Drive, strFilesstrTemp = sysdrv & "\Temp"Drives = Array("C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", _ "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")For Each Drive In Drives If fs.FileExists(Drive & ":\WIN51") Then strFiles = Drive & ":\EXTRAS\"NextNote that in my case the only directory I need access to on the CD/DVD is the one called "EXTRAS." Obviously you can modify to suit your own needs. The underscore and CR entered for readability only in the case of the batch code. The underscore and CR in the VBscript is for readability also, but is acceptable and functioning code. Link to comment Share on other sites More sharing options...
gunsmokingman Posted November 1, 2004 Share Posted November 1, 2004 (edited) Here one that I made, It makes A Vbs Script call Cd.vbsIt than it starts the CD.vbs passes the Drive letter To This CD.cmdWhich Is Than Echo Back To The Cmd Screen As The Drive LetterSo To Use It In Your Bat Files Is To Edit Out Below This>> Cd.vbs echo ts.CloseAdd What You Need Below To Match Your NeedsIt Will Only Echo Back What Your Cd Letter Is, As It Is.echo offmode con: cols=55 lines=2title CdVarcolor 9f> Cd.vbs echo Dim ts>> Cd.vbs echo Dim strDriveLetter>> Cd.vbs echo Dim intDriveLetter>> Cd.vbs echo Dim fs 'As Scripting.FileSystemObject>> Cd.vbs echo Const CDROM = 4>> Cd.vbs echo On Error Resume Next>> Cd.vbs echo Set fs = CreateObject("Scripting.FileSystemObject")>> Cd.vbs echo strDriveLetter = "">> Cd.vbs echo For intDriveLetter = Asc("A") To Asc("Z")>> Cd.vbs echo Err.Clear>> Cd.vbs echo If fs.GetDrive(Chr(intDriveLetter)).DriveType = CDROM Then>> Cd.vbs echo If Err.Number = 0 Then>> Cd.vbs echo strDriveLetter = Chr(intDriveLetter)>> Cd.vbs echo Exit For>> Cd.vbs echo End If>> Cd.vbs echo End If>> Cd.vbs echo Next>> Cd.vbs echo Set ts = fs.CreateTextFile(Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) ^& "cmd", True, False)>> Cd.vbs echo ts.WriteLine "set " ^& Left(WScript.ScriptName, InStr(WScript.ScriptName, ".") - 1) ^& "=" ^& strDriveLetter>> Cd.vbs echo ts.Closeping -n 1 127.0.0.1>nulstart wscript.exe Cd.vbsping -n 3 127.0.0.1>nuldel cd.vbscall cd.cmddel cd.cmdclsmode con: cols=55 lines=5color 2becho.echo Your Cd Is %CD%echo.echo set cdrom=%CD%echo.ping -n 4 127.0.0.1>nulexit Edited February 6, 2007 by gunsmokingman Link to comment Share on other sites More sharing options...
GreenMachine Posted November 1, 2004 Share Posted November 1, 2004 I believe what is really being looked for in 99% of these cases is the cd letter from which windows was installed: that is where the CD is ...FOR /F "TOKENS=3" %%I IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "SourcePath" ^| FINDSTR "SourcePath"') DO SET CDROM=%%~dI Link to comment Share on other sites More sharing options...
jdoe Posted November 1, 2004 Share Posted November 1, 2004 but is acceptable and functioning code.Not reallyYou forgot to declare fsTo match your thread title....Set fs = CreateObject("Scripting.FileSystemObject")Drives = Array("C:", "D:", "E:", "F:", "G:", "H:", "I:", "J:", "K:", "L:", "M:", _ "N:", "O:", "P:", "Q:", "R:", "S:", "T:", "U:", "V:", "W:", "X:", "Y:", "Z:")For Each Drive In Drives If fs.FileExists(Drive & "\WIN51") Then CDROM = Drive Exit For End IfNextFor Windows XP only because of WIN51 Link to comment Share on other sites More sharing options...
RogueSpear Posted November 1, 2004 Author Share Posted November 1, 2004 @jdoe oops. That's what I get for copy/pasting code out of a much larger script. Thanks for the correction.@GM One thing I do right out of the gate is copy over i386 to the hard disk and then reassign that registry key. Also, was just showing a way to go about it using VBscript. Link to comment Share on other sites More sharing options...
GreenMachine Posted November 1, 2004 Share Posted November 1, 2004 ... @GM One thing I do right out of the gate is copy over i386 to the hard disk and then reassign that registry key. Also, was just showing a way to go about it using VBscript.Sorry: Wasn't trying to show you up ... I re-assign that key myself, after changing the drive letters to something more logical. At the same time I create a new system wide environmental variable with the CD letter.The reason I went this route was that I would sometimes get "Drive not ready" errors. I cannot remember which kind of drive did it, but not all like being referenced when empty. Link to comment Share on other sites More sharing options...
RogueSpear Posted November 1, 2004 Author Share Posted November 1, 2004 @GM, another thing is that I seem to have a lot of difficulties with batch compared with VB. I used to use batch exclusively years back, and I never did take to some of the more complicated things. So I started to fiddle with Kix, which is very nice BTW if you want to disable WSH for security purposes, and I eventually settled on VBscript.Also, that was nice tight code; only one line. I always like the simple, yet effective solutions to a problem.One last thing. Have you looked at the batch files in BTS's Driver Packs? Made me go Felt almost like I never wrote a line in my life. Good stuff. 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