Sponsored Links
These little files can save time and effort by automating actions that would otherwise be done manually. It seems something of a dark art though, with not many techies I know being able to write good ones. There is nothing I like better than a challenge! The first thing to remember is that Batch Files can be as simple of as complex as you want or need them to be. They can take a lot of drudgery out of server maintenance and even help with normal desktop tasks.
Making one is easy enough, you just use notepad and save it as a .bat file. So why does it seem like black magic?
The tidiest way of playing is to create a folder somewhere and call it something useful like “BatchFiles”. The exact setup I will leave to you, but create this file, then create an empty notepad file within the folder. Call it what you like, mine is imaginatively titled “batch1″.
I have created two batch files for my games machine.
It’s a simple alternative to using Hardware profiles. One to minimize services and other system drains while I play games, and the other to restore the original settings. I will demonstrate how to create this later, but for now let’s go back to the eighties.
Type this into notepad;
@ECHO OFF
ECHO.
ECHO
HuxleyTech is the best!
ECHO.
PAUSE
CLS
EXIT
Save this as Batch1.bat, ensuring that you remove the .txt suffix. Double click the file and see what happens.
Now this is entry level batch scripting, but it gives you an idea of how they work.
ECHO OFF will not display anything when the script executes.
ECHO. Will display a blank line.
ECHO display whatever text follows.
CLS clears the screen
Exit should speak for itself really…
You can do all sorts with these files, and the scope is way beyond this article. However I shall show you how to create a basic file to start and stop Windows services. This is the basis of my “Games.bat”.
The two commands you are going to need are generic Windows ones;
NET START and NET STOP. These commands start and stops Windows services. For example.
NET STOP “Messenger” will stop the Messenger service from running. Understandably
NET START “Messenger” will start it again. I have a lot of the Windows services disabled, or “manualled” as default anyway so this list may not reflect your own setup. Some tweaking to your own specifications will be needed here.
So my Games.bat looks something like this; NET STOP “Alerter” NET STOP “Application Layer Gateway Service” NET STOP “Cryptographic Services” NET STOP “DNS Client” The list goes on for a bit, but you get the idea… A quick double click and my machine is a leaner, meaner gaming machine. A second batch file called “Normalise.bat” looks a bit like this;
NET START “Alerter” NET START “Application Layer Gateway Service” NET START “Cryptographic Services” NET START “DNS Client” To make the job a little easier you can export a list of services to use in this file. Go to Control Panel, Admin Tools, Services. Select the Action menu then Export. The format is up to you…
This next one is quite useful as it requests a password for a folder. Once you create it in notepad you must insert your own password and designated folder directory into the proper place! There are three places you need to enter information, marked with ***. Where it says ENTER PASSWORD, this is where you need to enter whichever password you want to use. For example; “Set password=Huxley”.
@echo off
title Password Protection
color 0a
set /a tries=3
set password=***ENTER PASSWORD ***
:top
echo.
echo ———————————————-
echo.
echo Folder Password
echo.
echo ———————————————-
echo You have %tries% attempts left.
echo Enter password
echo ———————————————-
set /p pass=
if %pass%==***ENTER PASSWORD *** (
goto correct
)
set /a tries=%tries -1
if %tries%==0 (
goto penalty
)
cls
goto top
:penalty
echo Sorry, too many incorrect passwords, shutting down.
start shutdown -s -f -t 35 -c “SHUTDOWN INITIATED”
pause
exit
:correct
cls
echo ———————————————-
echo Password Accepted!
echo.
echo Opening Folder…
echo ———————————————-
explorer ***ENTER FOLDER PATH HERE***
pause
The last input needed is the folder path. For example “explorer c:/MyDocuments/Stuff”.
Batch files are a massive subject, and I have only just scraped the surface here. I may go into a little more detail another time.
No related posts.

