Instructables

How to Create your own Commands with Batch

Picture of How to Create your own Commands with Batch
--EDIT1--
Corrected incorrect information on step 2 (to do with limitations with parameters).

--EDIT2--
Added a couple of lines about an auto-installer in step 4.

This instructable will cover the basics of creating your own commands (and even installing them on others computers) which you can use to further cut down the amount of work you need to do.

Some things you should have:
  • A Windows computer (preferably modern)
  • A USB (for transporting the files around)
  • A basic to advanced understanding of the syntax involved with batch commands (this is not a tutorial to help you learn about commands, this is a tutorial about making your own
  • Basic computer know how (for instance, knowing how to navigate through folders)

If you don't have a basic understanding of the syntax involved with batch scripts and the like, feel free to either search for a tutorial, ask questions or comment on something you don't understand.


 
Remove these adsRemove these ads by Signing Up

Step 1: What to make?

Picture of What to make?
Before you create your world-famous new command, you need to figure out what to make.

Most commands have one specific purpose (such as the REN command), and each switch adds some more functionality to that command. Most of these commands were made because it would be impossible to do a certain task (that batch files are commonly used for) without them. Unfortunately, you cannot make a command that will make something possible that has never been possible before (because if you're making it, it's possible). So, the best thing to base your command around is to save time. 

So, ask yourself, What do I do frequently that takes a long time to program in? 

If you're not that much of the typical "hardcore programmer" (you're using batch here, so not many of you will match that term, it was purely to get my point across), then you might not need a function to save time, because you don't do that much.

In that case, ask yourself something along the lines of Which command lacks something?

That basically means, what command are you not happy with and you think you can do better?

Unfortunately, you can't just modify the code within the commands, so you have to resort to making a new command (such as SETX).



I probably should have explained how the command line (cmd.exe) parses commands. Well, looks like I found my topic for the next section.
Nice tutorial, but your little dice game is weird. It didn't work for me, I had to change "random" to "%random%" but then, I still couldn't figure out the problem
Prof. Pickle (author)  Computer Ninja5411 months ago
Did you have the other file in the same directory (random.bat)?

Hey, Prof. Pickle, since Cmd.exe uses other files for commands (if u don't get what i'm saying, I am basiclly (spelled wrong) saying the cmds aren't built into command prompt) then wouldn't you be able to find the files it uses and edit them?

I know they would be invisible but you can make all files in windows visible by tinkering with the folder options>view settings.

Please reply - Jax B.

Prof. Pickle (author)  TheJaxFiles3 months ago

Most commands that the command prompt uses are in executable format, written in C++. You can re-write the command, compile it and replace the original, but other than that...

ALSO Another question! This is my program i've put together (some of it)

:home
title Log in to MyComputerAdmin
cls
ping localhost -n 2 >nul
color 0c
echo===--Made by Jax Brachetti--===
ping localhost -n 2 >nul
color 0d
echo MCA Account Login/Register *Any user/password can be used to sign up, saved on YOUR Computer*
ping localhost -n 2 >nul
color 0c
echo =============
ping localhost -n 2 >nul
color 0e
echo Found any glitches/Bugs? Report them at http://jaxdownloads.webs.com :)
ping localhost -n 2 >nul
color 0a
echo Version: 4.1.4.6
ping localhost -n 2 >nul
echo.
ping localhost -n 2 >nul
color 0e
echo [1] Log In
ping localhost -n 2 >nul
color 0b
echo [2] Sign Up
ping localhost -n 2 >nul
color 0a
echo [3] Exit
ping localhost -n 2 >nul
color 0d
echo [4] Calculator
ping localhost -n 2 >nul
color 0c
echo [5] Delete all user accounts!
ping localhost -n 2 >nul
color 01
echo [333] UNLOCK SECRETS OF THE UNIVERSE! (Seizure Warning)
echo.
echo.
ping localhost -n 2 >nul
color 0a
echo Need help? Just type 1-5 and what each number will take you to is listed above!
echo.
color 07

How would I make it so it displays all this text in all of those different colors at the same time? (doesn't have to be in the same colors) Just please tell me how! I have been searching for hours on youtube,instructables,google,yahoo,mozilla firefox,internet explorer, WELL PRETTY MUCH EVERYTHING!

mvaghadiya10 months ago
This is very useful for me. Thank you sir.

can you tell me how to set help utility for my own command???
Prof. Pickle (author)  mvaghadiya10 months ago
I like to put it in sort of an internal "function" which I'd call when they didn't do something right (regarding to arguments). Here's an example:

@setlocal & @echo off
if %1 equ "" goto :help
::code

:help
echo This is how you use this command...
This I knew. But what about when someone(user) type "Help " ???
Prof. Pickle (author)  mvaghadiya10 months ago
If they put it in as an argument (example: command help, command /?)

@setlocal & @echo off
if "%1" equ "help" goto :help
if /i "%1" equ "/?" goto :help
::code

:help
::info
Very nice tutorial! This was very informative! I will be sure to try it.
Prof. Pickle (author)  SoulEater8211 year ago
Glad you liked it. Remember to share what you make!
I haven' made anything yet, I might later on today, right now I am in the middle of starting a text-adventure game. I haven't done batch in so long... I finally recovered my files from my old computer and I saw this tutorial and it got me into batch again. :D
Great tutorial! out of my head..surely I will try it....
Prof. Pickle (author)  code source1 year ago
Glad you liked it.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!