Automating Your Configuration with a Daily Batch

Batch files are still an important part of your system, especially if you find that you need to perform certain configuration tasks every day. Both Administering Windows Server 2008 Server Core and Windows Command-Line Administration Instant Reference discuss batch files, but this post is about a practical example of a batch file in daily use.

My system has a daily batch file. It runs every morning when I start the system up. (To save electricity, I do turn off my system every night and find that things also run better because I do.) The main reason for using a daily batch file is to configure my system so I don’t end up performing the same repetitive tasks every day. I tell the computer what to do and it performs the required configuration for me. After I get my cup of coffee, my system is ready to go—fully configured for my use.

The daily batch file appears as an entry in the Startup folder on my system. Placing the file in the Startup folder means that it runs automatically, but that I can also easily disable the batch file should I wish to do so. Use these instructions to add a daily batch file to your Startup folder:

 

  1. Choose Start > All Programs. You see a list of entries including Startup.
  2. Right click Startup and choose Open from the context menu. (Unless you want everyone to use the same automatic batch file, you don’t want to choose Open All Users.) You see a copy of Windows Explorer open for the Startup folder.
  3. Right click anywhere in the right Windows Explorer pane and choose New > Text Document from the context menu. Windows will create a new text document named New Text Document.txthowever, only the New Text Document part of the filename is highlighted.
  4. Highlight the entire filename and type Daily Tasks.bat. Make absolutely certain that you also overwrite the .txt part of the filenameDaily Tasks.bat.txt won’t do anything for you.
  5. Press Enter. You see a Rename dialog box that asks whether you’re sure that you want to change the extension of the file.
  6. Click Yes. Windows renames the file.

Of course, the file is empty at this point. Right click Daily Tasks.bat and choose Edit from the context menu. Windows will open a copy of Notepad with the empty batch file loaded. At this point, you can start typing commands for Windows to execute automatically when you start up in the morning. It’s possible to execute many commands directlyespecially those that are meant to execute at the command line, such as W32Tm /Resync, which forces an update of the system clock. Other commands require that you use the Start command to execute them. For example, you might want to tell Firefox to automatically open the Astronomy Picture of the Day site using this command:

 

Start “C:\Program Files\Mozilla Firefox\Firefox” http://antwrp.gsfc.nasa.gov/apod/

<font<> <font<>The Start command starts Firefox in this case. It passes the URL you provide to Firefox as a command line parameter. Obviously, the application must support command line parameters for this technique to work. More applications than you might think do support command line parameters (many undocumented), so a little research can provide a lot in automation.

Any command that you can execute in any other batch file is also available when you’re starting Windows. There is one special consideration. You’ll likely find that executing one command immediately after another causes timing problems when Windows is initially starting. For example, if you try to open several Web sites, you’ll find that Windows actually misses opening a few unless you provide some sort of wait period between commands. Fortunately, the Choice command fulfills this task perfectly. For example, the following command provides a 15 second delay that you can insert between commands:

 

@CHOICE /C:N /N /T:15 /D:N


Using this command the user won’t even be aware of the delay. The @ symbol makes the Choice command invisible. The /C command line switch provides the available choices (which consists solely of N in this case). The /N command line switch hides the list of choices from view. You create the actual timeout value using the /T command line switch, which is set for 15 seconds in this example. However, the /D command line switch actuates the delay by automatically choosing N after the 15 seconds. In short, this entire command line is a wait statement.

If you want your batch to run more or less invisibly, make sure you start it with an @Echo Off command. Otherwise, every command appears in the window. It’s helpful to check for errors when you first put the batch file together and when you make changes. Adding an @Pause at the end of the batch file keeps the command window visible so you can check for errors.

After you finish the batch file, you can execute it as you would any other batch file. The only difference in this situation is that this batch file executes automatically each day because it resides in the Startup folder. When you need to make changes to this file you can choose Start > All Programs > Startup, then right click Daily Tasks.bat, and choose Edit from the context menu. The file will open in Notepad for you.

This is one of the more interesting and useful ways to employ batch files. What are your favorite batch processing techniques? Let me know at [email protected].

 

Rod Stephens’ Visual Basic Programming 24-Hour Trainer

Learning a new skill, such as programminglearning it quickly and easily, is much harder than it sounds, but “Rod Stephens’ Visual Basic 24-Hour Trainer” makes the task considerably easier. The book begins with possibly the best Introduction I’ve ever seen. The author tells you precisely how to use his book to learn how to code in Visual Basic in a short interval. Additionally, he makes it clear what the book won’t tell you. This is most definitely a book for the rank beginnersomeone who has never written code before and the author makes it clear that better educated developers need not apply. (More advanced readers will benefit more from another of Rod’s books, “Visual Basic 2010 Programmer’s Reference“.)

The chapters tell you how to perform most basic tasks associated with desktop applications. You won’t find any Web development techniques in this book, but the author makes that clear in the Introduction. The reason for focusing on the desktop is that it provides a controlled environment that works anywhereno Internet connection required, no special setup needed. All you need is your system and Visual Basic.

The first chapter is the usual description of how to get Visual Basic installed on your system. Rod discusses a few different options and doesn’t wimp out by covering only Visual Basic 2010 Express Edition like many beginner books do. Because of the target audience for this book, Visual Basic 2010 Express Edition works fine.

The book takes the usual college approach of starting with a basic application, working through variables and structures, and then moving toward more complex application types. You learn all of the basics of working with classes, printing documents, working with the clipboard, and other usual fare for a book of this type. Rod does provide a couple of nice perks such as working with LINQ and databases using the entity framework. The goal is to learn how to use Visual Basic at a basic level, so these exercises will serve the reader well. Someone looking to start by creating a relatively complex example almost immediately will be disappointed. I know that some readers look for this approach now and Rod’s book definitely won’t serve their needs; this book is more traditional (and proven) in its approach.

Each of the chapters provides several methods to learn the material. You can read about the technique, try it yourself on your machine, work through exercises, and even watch a video. Most readers will find a technique that works well for them. Rod suggests using some or ideally all of the techniques to obtain a better learning experience.

The videos are a nice touch and Rod does them well. The longest video I watched came in at 17 minutes, the shortest at 4 minutes. He has a nice speaking voice and an easy manner of approaching the topic. The reader should definitely feel at ease during the presentation. Rod doesn’t resort to humor to cover up a lack of depth in his book. It’s not that he’s incredibly serioushe’s simply straightforward and businesslike in his approach.

Will you actually get through this book in 24 hours as the title says? I doubt it. I tried out a number of the chapters and found that I averaged about an hour in doing them fully (including the exercises) at a rapid pace. There are 39 chapters in the book for a total of 39 hours of training as a minimum. Even if you attack the book at a rabbit-like pace and skip some of the features, you still won’t get through it in 24 hours and manage to gain anything worthwhile. I’d suggest setting aside at least 40 hours of focused time to get through this tome.

The bottom line is that this is a great book for the rank novice to learn a new skill and discover the joys of programming. It’s not the sort of book that anyone who has written code before will want and it’s also not the sort of book that the impatient reader will find helpful. Rod has done a marvelous job of presenting a complex topic in a manner that will help most people get up to speed working with Visual Basic in a short time.
 

Delimiters and Batch Files

The example on page 402 of Windows Command-Line Administration Instant Reference produces the correct result. You see the result of passing various bits of information between two batch files. However, as someone wrote to me recently, the output from the Batch2.BAT file isn’t the result you might expect. Instead of showing the entire %PATH% environment variable, you see just the first part of this environment variable as shown here.

BatchFile01

The reason you only see C:\Program as the environment variable output is the fact that %PATH% contains delimiters. There are a number of characters that the command prompt uses as delimiters, separators between elements in a single string. My testing shows that the space, tab, and semi-colon are three characters that always act as delimiters within a batch file. Of course, delimiters are extremely useful when you want to use one string to hold multiple elements for processing, but they can also cause interesting results, such as in this case where only part of the %PATH% environment variable appears in the output.

Of course, you’re probably asking how to obtain the entire environment variable as output. A simple change to Batch1.BAT makes this possible as shown here.

@ECHO OFF
Call Batch2.BAT
Call Batch2.BAT Passed %1 "%PATH%"
ECHO In Batch 1
GOTO :EOF
ECHO Goodbye

Notice that %PATH% now appears within double quotes. This change tells the command processor not to process the information within the %PATH% environment variable as separate entities. With this change you see the following output.

BatchFile02

Now you’re seeing the entire environment variable in the output. It’s important to note this difference in processing strategies when creating batch files of your own. What other batch file quirks have you encountered. Let me know at [email protected].

Considering the Economics of Accessibility

People have asked in the past which book of mine is my favorite. I have a number of answers to that question. In one respect or another, all of my books are my favorite because they all answer different questions and help a different group of people. As I’ve mentioned in the past, the reason I write is because I truly enjoy helping others.

My reasons for writing “Accessibility for Everybody: Understanding the Section 508 Accessibility Requirements” are many. However, one of the biggest reasons that I wrote it is because there are good economic reasons to make applications accessible to everyone. Not all of these reasons have a direct monetary impact, but I do express them in the first chapter of the book. The fact of the matter is that if your application isn’t accessible, you’re costing your company time and money. If you’re a store owner, you’re losing money every second that your organization uses applications that aren’t accessible.

Many
people associate accessibility with those who have special visual or
audio needs.  However, accessibility affects quite a large group of
people, including those who are colorblind. Did you realize that about 8% of the male population is colorblind,
which means that if your application isn’t accessible to this group
that you’re losing out on 8% of your sales right off the top? Can you
really miss out on that many sales? In short, accessibility is truly for everyone and everyone includes you.

It amazes me that some organizations just don’t seem to get it. Accessibility affects more than those people across the street; they affect you personally. At some point in life, you’re going to need an accessibility aid. Our eyes get older and can’t see as well, the ears refuse to hear, things wear out. So, the accessibility features you add to an application today will ultimately help you in some way. It’s the reason that I read about lawsuits such as the one between the National Federation of the Blind, NFB, and Google, and have to scratch my head. I have to wonder why such a lawsuit is even necessary.

Another reason I wrote my book is to show how easy it is to make applications accessible and to inform my readers about the laws regarding accessibility (laws that our government doesn’t enforce).  Creating an accessible application with the tools available today isn’t a major undertaking. In many cases you’re looking at a few extra minutes to add features such as speed keys and titles that a screen reader can read (the same titles appear as balloon help that sighted users also rely upon). It’s true that applications that make heavy use of full animation or video can become harder to make accessible, but these applications are in the minority. Most business applications require very little extra work.

If you think buying a book to learn about accessibility is just too expensive, I encourage you to make use of the free resources available on the Internet. Companies such as Microsoft want you to create accessible applications because they realize that it’s in their best interest to do so. These resources are incredibly easy to use and they make life easier for everyone. I’m always happy to hear about your insights regarding accessibility, so feel free to contact me at [email protected].

 

A Potential Eye Gaze System Replacement

I view the computer as a great equalizer. People who have special needs can rely on a computer to give them access to the world at large and make them productive citizens. In fact, I’m often amazed at what a computer can do in the right hands. People who used to be locked away in institutions are now living independently with help from their computer. That’s why I read a ComputerWorld article today, “Look, no hands! G.tec uses brain interface to tweet” with great interest. I don’t think this system could replace eye gaze systems for those who need them today, but the system holds great potential as an eye gaze system replacement in the future.

So, just what is an eye gaze system? Imagine you have two cameras mounted on either side of a monitor. The cameras are focused on someone’s eye position. As the person moves their eyes to look at a letter on a card above the monitor, the cameras record the position and use the information to tell the computer what letter to type. Of course, eye gaze systems can be used for more than simply typing letters. Some of these systems are extremely complex and can record the viewer’s gaze at any position on the monitor. Check out the LC Technologies setup as a modern example of what an eye gaze system can do.

The problem with eye gaze systems is that they can be slow, error prone, and tiring to use. Unless the system is properly calibrated, using eye gaze to interact with a computer can become frustrating and time consuming. This brain computer interface is exciting because it promises higher speed (0.9 seconds once trained) and the potential for errors is greatly reduced. However, this system is still in its infancy, so eye gaze systems will continue to be important for people with special needs well into the future. You can read more about accessibility topics in my book, “Accessibility for Everybody: Understanding the Section 508 Accessibility Requirements.” Let me know what you think of this new technology at [email protected].