Creating a .bat file, and using it. [Basic->Advanced]

Discussion in 'Archives' started by photoshopexp3rt, Sep 26, 2010.

Creating a .bat file, and using it. [Basic->Advanced]
  1. Unread #1 - Sep 26, 2010 at 11:30 PM
  2. photoshopexp3rt
    Joined:
    Jan 25, 2009
    Posts:
    620
    Referrals:
    1
    Sythe Gold:
    5

    photoshopexp3rt Forum Addict
    Banned

    Creating a .bat file, and using it. [Basic->Advanced]

    Hello everyone, Jordan here! Today, I will be showing you how to create a standard .bat file, and use it to your advantage.

    First off, open a new notepad file, and type "@echo off"

    [​IMG]

    Secondly, you can type a message, make it look as such:
    [​IMG]

    Next, what you'll do is save this as test.bat, and then go to the destination you saved it to, open it up, and you should get this:
    [​IMG]

    I would go into explaining Echo off/on, but it's not important, really. All you need to know is:
    Echo off: No directories will be shown. (Only what you put in.)
    Echo on: Directories will be shown. (Example: C:\Windows\Users\Test.bat Hey!)

    Now, try this!
    Type in this line of text:
    [​IMG]

    What this does is, makes it where, when you press the key to continue, the second line will show up...such as in the following picture.
    [​IMG]

    Now that you've mastered the basics, let's try some intermediate-type CMDs.
    Open up your test file (test.bat), and type in the following information:

    [​IMG]

    This is the result you should get :)
    [​IMG]

    Now, for this next part, go ahead and create a new folder on your desktop, and name it TestFolder1. Inside this folder, place a picture. Rename the picture to Testpic1, then come back to this guide!
    Alright, got it all set up? Awesome. Now, open your test.bat with notepad (Right Click -> Open with -> Notepad)
    Erase everything inside, and replace it with:
    Code:
    @echo off
    echo We are testing "start" and "remark"
    rem title Testfolder1
    start testpic1.png (you can replace this with whatever extension your pic is.)
    pause
    Note: You can replace "start XXXXXX" with any file you wish, just be sure to type it *exactly* as it is saved!
    Here is the output of the project above:
    [​IMG]

    Alright, guys, had enough of the easy peasy stuff? Let's get advanced.

    First off, open your Test.bat in a notepad file, and completely clear everything, and start fresh.

    Now, type the following information into your document:
    Code:
    @echo off
    echo Testing for Photoshopexp3rt's guide on Sythe!
    echo If you want to do math type 1 and press enter
    echo If you want to see a picture type 2 and press enter
    set /p option=
    if '%option%'=='1' goto :math
    if '%option%'=='2' start testpic1.png(or any extension)
    
    :math
    echo 79x19.2=?
    pause
    Now that that's all typed up, give it a shot, and save your .bat file, and then go open it up! This *should* be the output! :)
    [​IMG]

    Awesome! Now, let's move on to using "Calls". What a call does, is import a .bat file into your current .bat file, now, to do this, simply type the following information in! (After clearing your slate from the previous example.)
    Code:
    @echo off
    echo W00t, I know the basics of BATCH! Thanks photoshopexp3rt!
    pause
    cls
    call call.bat
    
    Now, save your file!

    now STOP HERE!

    Before opening this batch file, create a new batch file, by going the following:
    1. Open notepad.
    2. input the following information:
    Code:
    @echo off
    echo Hey! Look, I'm using Calls!
    pause
    The result should look similar to this:
    [​IMG]

    Amazing job so far! Let's see...how can we make it even more advanced...Let's make a digital clock! :)

    As always, before we continue, open your default test.bat, and clear everything inside.
    Now, type the following information (you may wanna just copy/paste):
    Code:
    @echo off
    color 09
    setlocal enabledelayedexpansion
    set s1=ÛßÛ ÜÛ -ßßÛ ßßÛ Û Û Ûßß Ûßß ßßÛ ÛßÛ ÛßÛ
    set s2=Û Û- Û -Ûßß ßßÛ ßßÛ ßßÛ ÛßÛ-- Û ÛßÛ ßßÛ
    set s3=ßßß ßßß ßßß ßßß-- ß ßßß ßßß-- ß ßßß ßßß
    ::-----012345678901234567890123456789012345678
    :loop
    cls
    echo.
    for /f "tokens=1" %%u in ('echo %time%') do set t=%%u
    if "%t:~1,1%"==":" set t=0%t%
    set tim=%t:~0,2%%t:~3,2%%t:~6,2%
    set t1=!tim:~0,1!
    set t2=!tim:~1,1!
    set t3=!tim:~2,1!
    set t4=!tim:~3,1!
    set t5=!tim:~4,1!
    set t6=!tim:~5,1!
    :line1
    set /a pos=4*!t1!
    set x1=!s1:~%pos%,3!
    set /a pos=4*!t2!
    set x2=!s1:~%pos%,3!
    set /a pos=4*!t3!
    set x3=!s1:~%pos%,3!
    set /a pos=4*!t4!
    set x4=!s1:~%pos%,3!
    set /a pos=4*!t5!
    set x5=!s1:~%pos%,3!
    set /a pos=4*!t6!
    set x6=!s1:~%pos%,3!
    echo %x1% %x2% Ü %x3% %x4% Ü %x5% %x6%
    ::line2
    set /a pos=4*!t1!
    set x1=!s2:~%pos%,3!
    set /a pos=4*!t2!
    set x2=!s2:~%pos%,3!
    set /a pos=4*!t3!
    set x3=!s2:~%pos%,3!
    set /a pos=4*!t4!
    set x4=!s2:~%pos%,3!
    set /a pos=4*!t5!
    set x5=!s2:~%pos%,3!
    set /a pos=4*!t6!
    set x6=!s2:~%pos%,3!
    echo %x1% %x2% - %x3% %x4% - %x5% %x6%
    :line3
    set /a pos=4*!t1!
    set x1=!s3:~%pos%,3!
    set /a pos=4*!t2!
    set x2=!s3:~%pos%,3!
    set /a pos=4*!t3!
    set x3=!s3:~%pos%,3!
    set /a pos=4*!t4!
    set x4=!s3:~%pos%,3!
    set /a pos=4*!t5!
    set x5=!s3:~%pos%,3!
    set /a pos=4*!t6!
    set x6=!s3:~%pos%,3!
    echo %x1% %x2% ß %x3% %x4% ß %x5% %x6%
    :wait
    for /f "tokens=1" %%u in ('echo %time%') do set t=%%u
    if "%t:~1,1%"==":" set t=0%t%
    set tim2=%t:~0,2%%t:~3,2%%t:~6,2%
    if %tim2%==%tim% goto :wait
    goto :loop
    The result should be as follows:


    Oh dear, did I skip ahead way too fast?
    Well, join me next time in my EXTREME guide to .bat files, and I'll go into depth of how the clock was created!


    For now guys, this has been Photoshopexp3rt/Jordan.
    Thanks for viewing. If this has helped you at all, please, reply with a comment or some cool stuff you've come up with.

    BONUS:
    For reading my entire guide, you will now get to f**k around a little with a .bat command :p Enjoy this ;)

    1. Open a new notepad.
    2. Input the following information:
    Code:
    @echo off
    :A
    echo /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    color 1f
    echo /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    color 7b
    echo /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    color 3a
    echo /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    color 7c
    echo /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    color 8c
    echo /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    color 3f
    echo /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
    goto :A
    3. Save as Whatever.bat
    4. Open it and watch :D.
     
  3. Unread #2 - Mar 7, 2011 at 1:41 AM
  4. ini pure win
    Joined:
    Feb 10, 2011
    Posts:
    167
    Referrals:
    0
    Sythe Gold:
    0

    ini pure win The road to hell is paved with good intentions.
    Banned

    Creating a .bat file, and using it. [Basic->Advanced]

    I for one absolutely love batch and used to code batch a while ago. It'd be better if you actually explained why you typed a certain command, and what it does and break down the codes + symbols, rather than just telling someone to copy and paste it to do this function. Explain it, and you'll have a nice guide.
     
  5. Unread #3 - Mar 16, 2011 at 11:54 AM
  6. Divine blob
    Joined:
    Mar 14, 2007
    Posts:
    1,289
    Referrals:
    2
    Sythe Gold:
    0

    Divine blob Guru

    Creating a .bat file, and using it. [Basic->Advanced]

    A
    ADDUSERS Add or list users to/from a CSV file
    ARP Address Resolution Protocol
    ASSOC Change file extension associations•
    ASSOCIAT One step file association
    ATTRIB Change file attributes

    B
    BCDBOOT Create or repair a system partition
    BOOTCFG Edit Windows boot settings
    BROWSTAT Get domain, browser and PDC info

    C
    CACLS Change file permissions
    CALL Call one batch program from another•
    CD Change Directory - move to a specific Folder•
    CHANGE Change Terminal Server Session properties
    CHKDSK Check Disk - check and repair disk problems
    CHKNTFS Check the NTFS file system
    CHOICE Accept keyboard input to a batch file
    CIPHER Encrypt or Decrypt files/folders
    CleanMgr Automated cleanup of Temp files, recycle bin
    CLEARMEM Clear memory leaks
    CLIP Copy STDIN to the Windows clipboard.
    CLS Clear the screen•
    CLUSTER Windows Clustering
    CMD Start a new CMD shell
    CMDKEY Manage stored usernames/passwords
    COLOR Change colors of the CMD window•
    COMP Compare the contents of two files or sets of files
    COMPACT Compress files or folders on an NTFS partition
    COMPRESS Compress individual files on an NTFS partition
    CON2PRT Connect or disconnect a Printer
    CONVERT Convert a FAT drive to NTFS.
    COPY Copy one or more files to another location•
    CSCcmd Client-side caching (Offline Files)
    CSVDE Import or Export Active Directory data

    D
    DATE Display or set the date•
    DEFRAG Defragment hard drive
    DEL Delete one or more files•
    DELPROF Delete NT user profiles
    DELTREE Delete a folder and all subfolders
    DevCon Device Manager Command Line Utility
    DIR Display a list of files and folders•
    DIRUSE Display disk usage
    DISKCOMP Compare the contents of two floppy disks
    DISKCOPY Copy the contents of one floppy disk to another
    DISKPART Disk Administration
    DNSSTAT DNS Statistics
    DOSKEY Edit command line, recall commands, and create macros
    DSACLs Active Directory ACLs
    DSAdd Add items to active directory (user group computer)
    DSGet View items in active directory (user group computer)
    DSQuery Search for items in active directory (user group computer)
    DSMod Modify items in active directory (user group computer)
    DSMove Move an Active directory Object
    DSRM Remove items from Active Directory

    E
    ECHO Display message on screen•
    ENDLOCAL End localisation of environment changes in a batch file•
    ERASE Delete one or more files•
    EVENTCREATE Add a message to the Windows event log
    EXIT Quit the current script/routine and set an errorlevel•
    EXPAND Uncompress files
    EXTRACT Uncompress CAB files

    F
    FC Compare two files
    FIND Search for a text string in a file
    FINDSTR Search for strings in files
    FOR /F Loop command: against a set of files•
    FOR /F Loop command: against the results of another command•
    FOR Loop command: all options Files, Directory, List•
    FORFILES Batch process multiple files
    FORMAT Format a disk
    FREEDISK Check free disk space (in bytes)
    FSUTIL File and Volume utilities
    FTP File Transfer Protocol
    FTYPE Display or modify file types used in file extension associations•

    G
    GLOBAL Display membership of global groups
    GOTO Direct a batch program to jump to a labelled line•
    GPUPDATE Update Group Policy settings

    H
    HELP Online Help

    I
    iCACLS Change file and folder permissions
    IF Conditionally perform a command•
    IFMEMBER Is the current user in an NT Workgroup
    IPCONFIG Configure IP

    K
    KILL Remove a program from memory

    L
    LABEL Edit a disk label
    LOCAL Display membership of local groups
    LOGEVENT Write text to the NT event viewer
    LOGMAN Manage Performance Monitor
    LOGOFF Log a user off
    LOGTIME Log the date and time in a file

    M
    MAPISEND Send email from the command line
    MBSAcli Baseline Security Analyzer.
    MEM Display memory usage
    MD Create new folders•
    MKLINK Create a symbolic link (linkd)
    MODE Configure a system device
    MORE Display output, one screen at a time
    MOUNTVOL Manage a volume mount point
    MOVE Move files from one folder to another•
    MOVEUSER Move a user from one domain to another
    MSG Send a message
    MSIEXEC Microsoft Windows Installer
    MSINFO Windows NT diagnostics
    MSTSC Terminal Server Connection (Remote Desktop Protocol)
    MUNGE Find and Replace text within file(s)
    MV Copy in-use files

    N
    NET Manage network resources
    NETDOM Domain Manager
    NETSH Configure Network Interfaces, Windows Firewall & Remote access.
    NETSVC Command-line Service Controller
    NBTSTAT Display networking statistics (NetBIOS over TCP/IP)
    NETSTAT Display networking statistics (TCP/IP)
    NOW Display the current Date and Time
    NSLOOKUP Name server lookup
    NTBACKUP Backup folders to tape
    NTRIGHTS Edit user account rights

    O
    OPENFILES Query or display open files

    P
    PATH Display or set a search path for executable files•
    PATHPING Trace route plus network latency and packet loss
    PAUSE Suspend processing of a batch file and display a message•
    PERMS Show permissions for a user
    PERFMON Performance Monitor
    PING Test a network connection
    POPD Restore the previous value of the current directory saved by PUSHD.
    PORTQRY Display the status of ports and services
    POWERCFG Configure power settings
    PRINT Print a text file
    PRINTBRM Print queue Backup/Recovery
    PRNCNFG Display, configure or rename a printer
    PRNMNGR Add, delete, list printers set the default printer
    PROMPT Change the command prompt•
    PsExec Execute process remotely
    PsFile Show files opened remotely
    PsGetSid Display the SID of a computer or a user
    PsInfo List information about a system
    PsKill Kill processes by name or process ID
    PsList List detailed information about processes
    PsLoggedOn Who's logged on (locally or via resource sharing)
    PsLogList Event log records
    PsPasswd Change account password
    PsService View and control services
    PsShutdown Shutdown or reboot a computer
    PsSuspend Suspend processes
    PUSHD Save and then change the current directory•

    Q
    QGREP Search file(s) for lines that match a given pattern.

    R
    RASDIAL Manage RAS connections
    RASPHONE Manage RAS connections
    RECOVER Recover a damaged file from a defective disk.
    REG Registry: Read, Set, Export, Delete keys and values
    REGEDIT Import or export registry settings
    REGSVR32 Register or unregister a DLL
    REGINI Change Registry Permissions
    REM Record comments (remarks) in a batch file•
    REN Rename a file or files•
    REPLACE Replace or update one file with another
    RD Delete folder(s)•
    RMTSHARE Share a folder or a printer
    ROBOCOPY Robust File and Folder Copy
    ROUTE Manipulate network routing tables
    RUN Start | RUN commands
    RUNAS Execute a program under a different user account
    RUNDLL32 Run a DLL command (add/remove print connections)

    S
    SC Service Control
    SCHTASKS Schedule a command to run at a specific time
    SCLIST Display NT Services
    SET Display, set, or remove environment variables•
    SETLOCAL Control the visibility of environment variables•
    SETX Set environment variables permanently
    SFC System File Checke
    SHARE List or edit a file share or print share
    SHIFT Shift the position of replaceable parameters in a batch file•
    SHORTCUT Create a windows shortcut (.LNK file)
    SHOWGRPS List the NT Workgroups a user has joined
    SHOWMBRS List the Users who are members of a Workgroup
    SHUTDOWN Shutdown the computer
    SLEEP Wait for x seconds
    SLMGR Software Licensing Management (Vista/2008)
    SOON Schedule a command to run in the near future
    SORT Sort input
    START Start a program or command in a separate window•
    SU Switch User
    SUBINACL Edit file and folder Permissions, Ownership and Domain
    SUBST Associate a path with a drive letter
    SYSTEMINFO List system configuration

    T
    TASKLIST List running applications and services
    TASKKILL Remove a running process from memory
    TIME Display or set the system time•
    TIMEOUT Delay processing of a batch file
    TITLE Set the window title for a CMD.EXE session•
    TLIST Task list with full path
    TOUCH Change file timestamps
    TRACERT Trace route to a remote host
    TREE Graphical display of folder structure
    TYPE Display the contents of a text file•
    TypePerf Write performance data to a log file

    U
    USRSTAT List domain usernames and last login

    V
    VER Display version information•
    VERIFY Verify that files have been saved•
    VOL Display a disk label•

    W
    WHERE Locate and display files in a directory tree
    WHOAMI Output the current UserName and domain
    WINDIFF Compare the contents of two files or sets of files
    WINMSD Windows system diagnostics
    WINMSDP Windows system diagnostics II
    WINRM Windows Remote Management
    WINRS Windows Remote Shell
    WMIC WMI Commands

    XCACLS Change file and folder permissions
    XCOPY Copy files and folders
    :: Comment / Remark•

    http://ss64.com/nt/

    This could help.
     
< Cropping Images: The Fast and Simple way | [Closed] Plznate's Official Gold Donations Service [Over $5000 donated!] >

Users viewing this thread
1 guest


 
 
Adblock breaks this site