Add Ons - DevSource
DevSource: Microsoft Developer Resource DevSource Home Sponsored by Microsoft Home Add Ons Architecture Languages Techniques Using VS Forums
Home arrow Add Ons arrow Win Command of the Command Line Interface
Win Command of the Command Line Interface
By John Mueller

Rate This Article: Add This Article To:

Win Command of the Command Line Interface
( Page 1 of 7 )

Ever wonder if you could provide a faster way to use your application? Well, you can, using the command line interface.

People have predicted the death of the command line for many years. Unfortunately (or fortunately, as you perspective may dictate) the command line simply refuses to go away. In case you’re wondering, the command line is that DOS-like window where you can type commands, just as you always have since the days of DOS. Microsoft has even attempted to force people to use a command line alternative known as Windows PowerShell. Administrators love the command line. Instead of navigating a GUI to accomplish work, you type a command and the work is done in moments, rather than minutes. The command line also offers the opportunity for automation through batch files and scripts. If you know how to use the command line properly, you can do amazing things in less time than anyone else. No wonder the command line has refused to die.

Of course, you’re wondering what command line usage has to do with you and your application. It’s quite possible to add a command line interface to any console or Windows forms .NET application with incredible ease. Adding this support correctly can turn your slow moving GUI application into a speedy experience for any user—especially administrators. This article shows how to work with console applications first, and then Windows forms applications. By the time you finish this article, you’ll be able to reach out and grab the command line, and make it your own.

ADVERTISEMENT

Understanding the Command Line

The command line has been around for many years. Even though the command interpreter supplied with Windows is different from the one supplied with DOS all those years ago, the basics of operation remain the same. That’s right; when you view the command line, you see a tool that’s been around since before Windows was an operating system. Needless to say, there have been a few changes over the users, but the changes are surprisingly few. You still find some very old commands in there such as DIR and Copy. The techniques for creating batch files, essentially a very old kind of script, haven’t changed in all these years either. In short, administrators love this tool because it’s familiar and it’s relatively simple to use.

As I previously mentioned, I thought the command line was essentially going to die at one point because Microsoft was pushing Windows PowerShell so hard. However, they recently released a version of Windows called Windows Server 2008 Server Core (Server Core for short). When you start Server Core, all you see is a command line. Server Core lacks a Taskbar—there isn’t even a Desktop. Microsoft has cut so much that some of your favorite GUI utilities won’t work at all. However, the command line and all of the commands it supports work just fine. After working with Server Core for quite a while, I can truthfully say that this version of Windows is amazing. Every small to medium sized business out there should pick up a copy today—before Microsoft changes its mind. You can read more about Server Core at http://www.petri.co.il/understanding-windows-server-2008-core.htm and http://msdn.microsoft.com/en-us/library/ms723891(VS.85).aspx.

The best way to understand the command line is to work with it a bit. If you’re using Windows XP or earlier, you can simply choose Start | Programs | Accessories | Command Prompt and you’ll see a command line open. For those of you using a newer version of Windows, such as Vista, choose Start | Programs | Accessories, right click Command Prompt, and choose Run as Administrator from the context menu.

When you finally see the command line, type CD \Windows\System32 and press Enter. This command takes you to the System32 folder of Windows. Now, type Dir *.EXE /W and press Enter. The vast majority of those executables you see work just fine at the command line. What’s even more amazing is that this is just the tip of the iceberg. Windows is literally packed with executables that work at the command line. If you ever want to determine whether an executable works reliably at the command line, type the executable name, followed by the /? command line switch, and press Enter. Try it now by typing ChkDsk /? and press Enter. The Check Disk (ChkDsk) command will display usage instructions and tell you what task it performs.

Command line syntax works in a number of places in Windows, besides the command prompt you create. For example, you can use command line syntax in shortcuts to automate application starting. A number of the applications in my Startup folder use this feature. Adding command line syntax to your application also makes it possible to add the application to the registry. For example, you might want to associate a file extension with your application so that when the user double clicks a file with that extension, Windows can automatically open your application with the file loaded.

By now, you probably have a number of ideas for using the command line for your own applications. It’s helpful to look at the commands that Microsoft has put together to see how your applications should work at the command line. You can see a compilation of these commands in my book, “Administering Windows Server 2008 Server Core” (you can order it at http://www.amazon.com/exec/obidos/ASIN/0470238402/datacservip0f-20/).



 
 
>>> More Add Ons Articles          >>> More By John Mueller
 



Microsoft's Future: A Chat With Their CTO, Barry Briggs

Play Video >

All Videos >

Julia explores the Robotics Studio!

Read now >

Messages to Bill Gates!

Read now >

View Now
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.