Introduction: Batch File Butler

Picture of Batch File Butler

I have not found many online guides on how to make this, so I went ahead and made one myself. This is a batch file butler that serves as a control center, doing anything you tell it to do. This program can be made with just your average text editing program such as notepad, and a standard windows 7 OS. Hopefully after this step-by-step, your computer life will be that much easier.

Step 1: First Steps and Customization

We are going to start out with the basic settings and customizations of your butler. To begin, open notepad or any other text editing software. Copy the code down below into this text document.

Let's take a look at what the code down below does.

@echo off - This basically hides the behind the scenes code that is running and hides the confirmation display. This is to ensure that our script is as clean as possible.

color a - This sets the color scheme of our butler. Color a sets the background as default(black) and the text to light green. This is both optional and also can be customized. Color customization

:start - This is a place marker in our code that allows us to hop to this point at any given time. In this case, we have it as a point to go back to when a command is finished running. More on this later.

cls - This clears all of the information currently displayed on the butler. It's placed after the start marker so that all of the information displayed by the last used command is no longer there.

title butler - If you look on the top of every window that you have open, each has a title. The default title for our butler would be the name of the file, but we can change it to whatever you please. More on title command

echo Hello, how may I help you? - The echo command is the basic way of displaying information in a cmd or batch file. More on this later.

@echo off 
color a 
:start 
cls 
title butler 
echo Hello, how may I help you?

Step 2: Starting Your First Command.

This next part is teaching you how to create your first command, whether it be opening a file, returning information, opening a website, or starting a program.

To start the creation of your command, you enter the set command. This command creates a set, or collection of environmental variables that can be entered to execute any command. Let's just call this set main, since it contains all of our up front commands. More on set command

Next, is the if command. This is a universal command across all coding or scripting languages that provides feedback if certain information is true or false. In this case, if someone types in command, it will "goto" a marker somewhere else in the code that reads :command . More on if command

The commands following are the actual command itself. This command just returns with the text, "Test command returned successful!". After that, it pauses so the user can read the information. The pause will end when the user enters any key. "goto start" then reverts the user back to the beginning of the butler, where you can continue entering commands. More on goto command

set /p main=">"

if '%main%' == 'command' goto command

:command
echo Test command returned successful!
pause
goto start

Step 3: Customization of Commands.

This next step will show you a few things you can do with your commands, including opening files, returning text, navigating to a specific URL, color changing without editing code, and logoff/shutdown.

Opening programs/files - Opening anything requires the directory of said file. To open a file or program, type the code below into your file:

start C:\users\user\documents\file.txt

Opening anything within the Program files or Program Files(x86) requires one extra step. This example opens steam. More on start command

cd C:\Program Files (x86)\Steam
start Steam.exe

You can also use the start command for opening a URL:

start <a href="https://www.instructables.com">https://www.instructables.com</a>

Returning text - This is the most simple thing you can do with your commands. Whether this returns a set of random numbers, a password you need to remember, or a small joke.

The base command to all of these specific sets of information is echo. The example below returns the phrase, "Hello World!".

echo Hello World!

There are also a few variables that you can use with the echo command. The examples shown below return a set of random numbers, and the windows user accessing the program. More on echo command

echo %random%
echo %user%

Logoff/Shutdown - Logging off your current user or shutting down your computer is quite easy. since logoff is a subset of shutting down, we will only be using one command, shutdown.

shut down computer:

shutdown /p 

log off:

shutdown /l

As added security, you may want to create a yes/no option to continue with the logoff/shutdown. To do this, you must create another set of environmental variables with the set command.

<p>:logoff<br>echo log off?
set /p logyn=">"
if '%logyn%' == 'yes' goto logy
if '%logyn%' == 'no' goto start
goto start</p><p>:logy
shutdown -l</p><p>:shutdown
echo Shut down?
set /p shutyn=">"
if '%shutyn%' == 'yes' goto shuty
if '%shutyn%' == 'no' goto start
pause
goto start</p><p>:shuty
shutdown /p</p>

If you read the code correctly, you can tell that this provides the user with a yes/no choice to continue. You create a set for yes and no, if the user enters no, the code will cancel and go back to the start. More on shutdown command

Color Customization - This is a script I wrote that allows the user to make a temporary change to the color of the butler text. This uses the commands: "echo" "set" "if" and "color".

<p>:color<br>cls
echo type back to return
echo What color would you like the text to be?
echo type list for a list of colors</p><p>set /p color=">"</p><p>if '%color%' == 'list' goto list
if '%color%' == 'blue' goto color_blue
if '%color%' == 'gray' goto color_gray
if '%color%' == 'green' goto color_green
if '%color%' == 'aqua' goto color_aqua
if '%color%' == 'red' goto color_red
if '%color%' == 'purple' goto color_purple
if '%color%' == 'yellow' goto color_yellow
if '%color%' == 'white' goto color_white
if '%color%' == 'back' goto back</p><p>:list
cls
echo blue
echo gray
echo green
echo aqua
echo red
echo purple
echo yellow
echo white
pause
goto :color</p><p>:color_blue
color 9
pause
goto start</p><p>:color_gray
color 8
pause
goto start</p><p>:color_green
color a
pause
goto start</p><p>:color_aqua
color b
pause
goto start</p><p>:color_red
color c
pause
goto start</p><p>:color_purple
color d
pause
goto start</p><p>:color_yellow
color e
pause
goto start</p><p>:color_white
color f
pause
goto start</p>

Step 4: Checking Back

At this point, you should have learned how to:

Create basic batch settings

Create an environmental variable

Set up a command

Reset after every command

Customize output of command

Using everything you've learned, make a set of commands and also a help command explaining what each of your custom commands do. When you're finished, it should look something like this:

<p>@echo off<br>color a
:start
cls
:nonclear
title  butler
echo hello, how can I help you?</p><p>set /p main=">" </p><p>if '%main%' == 'steam' goto steam
if '%main%' == 'exit' goto exit
if '%main%' == 'logoff' goto logoff
if '%main%' == 'shutdown' goto shutdown
if '%main%' == 'help' goto help
if '%main%' == 'instructables' goto instructables
if '%main%' == 'color' goto color</p><p>:steam<br>cd C:\Program Files (x86)\steam\
start Steam.exe
pause
goto start</p><p>:exit<br>exit</p><p>:logoff</p><p>echo log off?</p><p>set /p logyn=">"
if '%logyn%' == 'yes' goto logy
if '%logyn%' == 'no' goto start
goto start</p><p>:logy
shutdown -l</p><p>:shutdown
echo Shut down?
set /p shutyn=">"
if '%shutyn%' == 'yes' goto shuty
if '%shutyn%' == 'no' goto start
pause
goto start</p><p>:shuty
shutdown /p</p><p>:help<br>
echo exit - closes this window
echo.
echo help - displays this menu
echo.
echo logoff - logs off this user
echo.
echo shutdown - shuts down the computer
echo.
echo steam - opens steam</p><p>echo.</p><p>echo instructables - opens the instructables homepage</p><p>echo.</p><p>echo color - Color customization</p><p>pause</p><p>goto start</p><p>:color<br>cls
echo type back to return
echo What color would you like the text to be?
echo type list for a list of colors</p><p>set /p color=">"</p><p>if '%color%' == 'list' goto list
if '%color%' == 'blue' goto color_blue
if '%color%' == 'gray' goto color_gray
if '%color%' == 'green' goto color_green
if '%color%' == 'aqua' goto color_aqua
if '%color%' == 'red' goto color_red
if '%color%' == 'purple' goto color_purple
if '%color%' == 'yellow' goto color_yellow
if '%color%' == 'white' goto color_white
if '%color%' == 'back' goto back</p><p>:list
cls
echo blue
echo gray
echo green
echo aqua
echo red
echo purple
echo yellow
echo white
pause
goto :color</p><p>:color_blue
color 9
pause
goto start</p><p>:color_gray
color 8
pause
goto start</p><p>:color_green
color a
pause
goto start</p><p>:color_aqua
color b
pause
goto start</p><p>:color_red
color c
pause
goto start</p><p>:color_purple
color d
pause
goto start</p><p>:color_yellow
color e
pause
goto start</p><p>:color_white
color f
pause
goto start</p>

Step 5: Saving the File and Executing

Saving - Once you are happy with what you have, save the file on your desktop as butler.bat . Make sure you delete the .txt file extension, or this will save as a basic text file.

Executing - Locate the Butler.bat file on the desktop or wherever you saved it. Open it by double clicking. Make sure to try every command you made, and if none work, right click the file and select edit. Once back in text form, locate and fix the bug in the code.

Thank you all for reading my guide, I hope you learned something :)

If you have any questions or find a problem with this instructable, please feel free to comment and correct me, this is my first time making one.

Comments

seamster (author)2015-08-26

Cool, thanks for sharing this.

About This Instructable

709views

7favorites

More by lokiloki19:Batch File Butler
Add instructable to: