pob Posted December 1, 2004 Share Posted December 1, 2004 hi, can anybody tell me if there is a idiots guide to making batch files around? i am very new to this unnatended thing, but only seem to be stumbling on this batch file thingy. sorry if this is in the wrong place...... Link to comment Share on other sites More sharing options...
Tsunami Posted December 1, 2004 Share Posted December 1, 2004 http://unattended.msfn.org/xp/batch_commands.htm Link to comment Share on other sites More sharing options...
pob Posted December 1, 2004 Author Share Posted December 1, 2004 erm.. cant understand that guide, thats why i asked for an idiots guide...( new to computers ). all the other stuff has basic walkthrus.. cept batch files. Link to comment Share on other sites More sharing options...
jdoe Posted December 2, 2004 Share Posted December 2, 2004 Try these links...http://www.student.oulu.fi/~vtatila/batch_tutorial.htmlhttp://www.robvanderwoude.com/index.html Link to comment Share on other sites More sharing options...
un4given1 Posted December 2, 2004 Share Posted December 2, 2004 First lesson.. it's no longer called "batch script" it's "command script" and technically you should use the extension .cmd instead of .bat. BAT is only for backwards compatability. Link to comment Share on other sites More sharing options...
jdoe Posted December 2, 2004 Share Posted December 2, 2004 First lesson.. it's no longer called "batch script" it's "command script" and technically you should use the extension .cmd instead of .bat. BAT is only for backwards compatability.I think your playing with words. A batch file is a batch file (.bat or .cmd)If you search in Windows help you find help about command-line only if you type "batch files". If you type command script you get nothing.From Windows help..Using batch files. With batch files, which are also called batch programs or scripts, you can simplify routine or repetitive tasks. A batch file is an unformatted text file that contains one or more commands and has a .bat or .cmd file name extension. When you type the file name at the command prompt, Cmd.exe runs the commands sequentially as they appear in the file.Can you give me something to read about this backward compatibity a links maybe? I'm curious. Link to comment Share on other sites More sharing options...
un4given1 Posted December 2, 2004 Share Posted December 2, 2004 Look at the description of a CMD file. It's "Windows NT Command Script." While Windows still recognizes BAT files and processes them the same, CMD is the proper extension for Post 2000 Windows and they are called COMMAND SCRIPTS. Link to comment Share on other sites More sharing options...
totoymola Posted December 2, 2004 Share Posted December 2, 2004 Welcome pob! Let's learn together.My one and only bible for using DOS commands is this. %systemroot%\help\ntcmds.chmI still want to learn more. Thanks jdoe for the links. Do you have some more? un4given1, I still don't understand the difference between .bat and .cmd. Maybe I'm just stupid but at first I thought they were the same. Link to comment Share on other sites More sharing options...
MHz Posted December 2, 2004 Share Posted December 2, 2004 un4given1, I still don't understand the difference between .bat and .cmd. Maybe I'm just stupid but at first I thought they were the same.A *.cmd file will not execute on a 9x operating system. Commands in a *.cmd file may not work for a 9x system. This difference ensures that scripts made for one type of system are not functional on another type of system. This is a major issue if they are treated the same. Link to comment Share on other sites More sharing options...
jdoe Posted December 2, 2004 Share Posted December 2, 2004 I still want to learn more. Thanks jdoe for the links. Do you have some more? Sorry, it's the only links I kept.The batch tutorial is good for learning for someone who want to start learning and the Rob van der Woude's Web site is a good reference about scripting in general.But if you want to learn more, Google "batch tutorial" will bring a lot of good sites.MHzA *.cmd file will not execute on a 9x operating system. Commands in a *.cmd file may not work for a 9x system. This difference ensures that scripts made for one type of system are not functional on another type of system.That make sense Link to comment Share on other sites More sharing options...
gunsmokingman Posted December 2, 2004 Share Posted December 2, 2004 (edited) Here A Cmd File That has A Simple Menu SystemI use it as a template and thought it would help you.It has 5 Spot in it 2 just Echo Back A Message 1\ Just Echo out your cd drive2\ Makes a Folder and Removes The Folder3\ Output A Text File And Than Open The Text File and than delet the text fileI have added some notes to it to help. That are in the script:: Any Text After These :: Are Notes In The script.Hope This HelpsECHO offcls:: WHERE THE MAIN MENU IS MADE, AND THE RETURN FROM THE OTHER PARTS OF THE CMD. SOFTWARE IS THE NAME THAT CMD LOOKS FOR :Softwareclsmode con: cols=60 lines=29COLOR 4eTITLE MAIN MENU:: THIS IS THE VBS PART THAT FINDS THE CD DRIVE> 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.Close:: TO SET THING LIKE SYSTEMDRIVE TO WHAT YOU WANTSET SD=%systemdrive%\SET SCD=%CDROM%Apps\:: THIS IS TO STOP THIS SCRIPT 1000=1 SECOND > Rst0.vbs ECHO Wscript.sleep 125>> Rst0.vbs ECHO Wscript.quit > Rst1.vbs ECHO Wscript.sleep 875>> Rst1.vbs ECHO Wscript.quit > Rst2.vbs ECHO Wscript.sleep 1875>> Rst2.vbs ECHO Wscript.quit > Rst3.vbs ECHO Wscript.sleep 2875>> Rst3.vbs ECHO Wscript.quit:: VARIBLES TO SAVE TIME FROM RETYPINGSET Size3=mode con: cols=45 lines=3SET Size5=mode con: cols=55 lines=5SET Size7=mode con: cols=55 lines=7SET Size11=mode con: cols=60 lines=11:: VARIBLES THAT START A ACTION. I AM TO LAZY TO TYPESET R0=start /w Rst0.vbsSET R1=start /w Rst1.vbsSET R2=start /w Rst2.vbsSET R3=start /w Rst3.vbs:: VARIBLES FOR TEXT. SET TXMSG1=PLACE A INSTALL ORDER HEREverECHO ÉÄÍÍÍÍÍ MY DEMO ÍÍÍ MENU ÍÍÍÍÍÍÍÄ»ECHO ºÄÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍĺECHO ºÄÄÄÄÄÄÄÄÄÄ Menu 1 ÄÄÄÄÄÄÄÄÄÄÄÄĺECHO ºÄ TYPE: ALL ĺ ECHO ºÄÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍĺECHO ºÄÄÄÄÄÄÄÄÄÄ Menu 2 ÄÄÄÄÄÄÄÄÄÄÄÄĺECHO ºÄÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍĺECHO ºÄ TYPE: CDD DEMO OF SET CD VAR ĺ This Uses A Vbs FileECHO ºÄÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍĺ That GeneratedECHO ºÄÄÄÄÄÄÄÄÄÄ Menu 3 ÄÄÄÄÄÄÄÄÄÄÄÄĺ In This Cmd ECHO ºÄÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍĺECHO ºÄ TYPE: MRD DEMO MKDIR RMDIR ĺECHO ºÄÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍĺECHO ºÄÄÄÄÄÄÄÄÄÄ Menu 4 ÄÄÄÄÄÄÄÄÄÄÄÄĺECHO ºÄÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍĺECHO ºÄ TYPE: OUT DEMO TEXTOUTPUT ĺ Simple Message ECHO ºÄÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍĺECHO ºÄÄÄÄÄÄÄÄÄÄ Menu 5 ÄÄÄÄÄÄÄÄÄÄÄÄĺECHO ºÄÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍĺECHO ºÄ TYPE: E ĺECHO ºÄÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍĺECHO ºÄ Q. Quit ĺ Cleans Up Any FilesECHO ÈÄÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍļ From ScriptTime /tECHO.:: SET /P prompts for input and sets the variable:: to whatever the user types:: You Can Name Anything After /P To What You Want:: The Name Must Match What Between >'%UC%'< After The /ISET UC=SET /P UC=Type What On The Menu Than Press Enter: :: To Increase The Amount Of Text To Input :: '%UC%'=='LEAVE HERE WITH THE AMOUNT SPACE BLANK':: BELOW 3 EXAMPLES THE DEFUALT IS SET TO 3 LETTERS:: SO NOW THE MENU WORKS WITH EITHER 1 2 3 OR 3 LETTERS:: The syntax in the next line extracts the substring:: starting at 0 (the beginning) and 1 character long EG A, 1, Z, 4::IF NOT '%UC%'=='' SET Choice=%UC:~0,1%:: starting at 0 (the beginning) and 2 character long EG AB, AT, ZZ ::IF NOT '%UC%'==' ' SET Choice=%UC:~0,2%:: starting at 0 (the beginning) and 3 character long EG BAT, CAT, MAT ,HATIF NOT '%UC%'==' ' SET Choice=%UC:~0,3%:: /I makes the IF comparison case-insensitiveIF /I '%UC%'=='All' GOTO Menu1IF /I '%UC%'=='CDD' GOTO Menu2IF /I '%UC%'=='MRD' GOTO Menu3IF /I '%UC%'=='OUT' GOTO Menu4IF /I '%UC%'=='E' GOTO Menu5IF /I '%UC%'=='Q' GOTO EndECHO "%UC%" is not valid. Please try again.CLSGOTO %UC%:: GOTO MEANS IT NEED A PLACE TO GO TO LIKE THE NAME SAYS.:: Menu1, Menu2, Menu3, Menu4, Menu5 ARE THE SPOTS IN THE BATCH FILE WHERE WE GOTO FROM SOFTWARE ::THAN WE GOTO SOFTWARE FROM Menu1, Menu2, Menu3, Menu4, Menu5:Menu1CLS%Size3%COLOR 9FTITLE MENU SELECTION 1ECHO.ECHO %TXMSG1% 1%R1%clsECHO.ECHO Back To Main%R1%GOTO Software:Menu2CLS%Size3%COLOR 9ETITLE MENU SELECTION 2 Example Varibleping -n 2 127.0.0.1>nulstart wscript.exe Cd.vbsping -n 2 127.0.0.1>nuldel cd.vbscall cd.cmddel cd.cmdcls%Size3%color 7bECHO Your Cd Is %CD%ECHO.SET cdrom=%CD%%R1% SET CDS=%CDROM%\Apps\mode con: cols=55 lines=3SET D=%CDROM%\Apps\%R0% Title Varible 1ECHO.ECHO %CDS%%R3% clsTitle Varible 2ECHO.ECHO %D%ECHO Completed%R3%GOTO Software:Menu3CLS%Size7%COLOR 2fTITLE MAKE A DIRECTORY mkdir %SD%\123tempECHO.ECHO That The Directory That Was just MadeECHO Cmd mkdir %SD%123tempECHO Using The Mkdir Cmd ECHO Passing The Varible I Made SD=%systemdrive%ECHO.pauseclsCOLOR CfTITLE REMOVE THE DIRECTORYrmdir /s /q %SD%123tempECHO.ECHO Cmd rmdir /s /q %SD%123tempECHO That Cmd to Remove The Folder That Was MadeECHO. pauseGOTO Software:Menu4cls%Size11%color f2TITLE PRODUCE A TEXT FILEECHO.echo offECHO THIS IS A TEST > TEST.TXTECHO. >> TEST.TXTdate /t>> TEST.TXTECHO HELLO THIS IS MESSAGE >> TEST.TXTECHO. >> TEST.TXTtime /t>> TEST.TXTECHO. >> TEST.TXTECHO "THIS IS A TEST > TEST.TXT"ECHO A Single Arrow Will Start A New File AndECHO Delete What Was There Before It.ECHO "THIS IS A TEST >> TEST.TXT"ECHO A Double Arrow Adds To The File And Leaves What There Un Changedpausecolor 7FTITLE LETS CHECK THE TEXT FILEclsECHO.Notepad.exe TEST.TXTECHO Completeddel TEST.TXT%R0%echo offGOTO Software:: Menu1, Menu2, Menu3, Menu4, Menu5 ARE THE SPOTS IN THE BATCH FILE WHERE WE GOTO FROM SOFTWARE ::THAN WE GOTO SOFTWARE FROM Menu1, Menu2, Menu3, Menu4, Menu5:Menu5clsmode con: cols=40 lines=5color 5eTITLE MENU SELECTION 5ECHO.ECHO %TXMSG1% 5%R1%clsECHO.ECHO Back To Main%R1%GOTO Software:endcls%Size3%color a9TITLE MENU THE ENDECHO.ECHO Here The End Clean Up Time?%R3%ping -n 1 127.0.0.1>nuldel Rst*.vbsdel Cd.vbsEXIT Edited July 18, 2005 by gunsmokingman Link to comment Share on other sites More sharing options...
BritishBulldog Posted December 2, 2004 Share Posted December 2, 2004 but this script is still no good if you have two or more cdrom drives, this only finds the first one. The find CDROM part must be changed to this and a cd.txt in the root of the CDROM.> Cd.vbs echo Dim ts >> Cd.vbs echo Set fso = CreateObject("Scripting.FileSystemObject")>> Cd.vbs echo For Each objDrive In fso.Drives>> Cd.vbs echo If objDrive.DriveType = "4" And objDrive.IsReady Then>> Cd.vbs echo If fso.FileExists(objDrive ^& "\cd.txt") Then strDriveLetter = objDrive>> Cd.vbs echo End If>> Cd.vbs echo Next>> Cd.vbs echo Set ts = fso.CreateTextFile("cd.cmd", True, False)>> Cd.vbs echo ts.WriteLine "SET CDDrive = " ^& strDriveLetter >> Cd.vbs echo ts.Close>> Cd.vbs echo WScript.Sleep 2000otherwise a good bit of coding :-) Link to comment Share on other sites More sharing options...
pob Posted December 2, 2004 Author Share Posted December 2, 2004 thanx jdoe, will chek out those linx Link to comment Share on other sites More sharing options...
pob Posted December 2, 2004 Author Share Posted December 2, 2004 happy to learn together totoymola, but beware i know absolutly zip about dos ... will check out them links from jdoe first. Link to comment Share on other sites More sharing options...
pob Posted December 2, 2004 Author Share Posted December 2, 2004 all links asume u know something about dos,... i dont . pls let me know if anybody has heard of a tutorial or an prog.... or anything. 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