Discussion Locked

XP command line eXPert!!!

0 helpful
32 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

The days of Dos 6.22 are long since gone and windows system is no longer dependant on the dos shell. However, Windows XP Pro includes it for backwards compatibility and it has not completely lost it's functionality. As a matter of fact it can still be used to create sophisticated batch tools. For example, a batch program in the startup folder containing the following line would log all network connections and append an update every 6 minutes: netstat -a 360 >> C:\netlogs\netconnectionmonitor.txt

I'm interested in developing my understanding of Dos 6.22 to include the advanced features of Windows XP pro (or even Server 2003 which I haven't experienced yet.) My goals are to extensively customize networking functions and data collection or manipulation. However I don't want to be have the responses to the question restricted by my goals. Constructive criticism only, references to reading material and real world deployment case studies are more than welcome they are appreciated.

Thankyou,

Berin Karjala, Network+

32 replies

by d_bones

Have you tried Windows Scripting instead. Far more powerfull. Techrepublic has issued several tutorials on this. Good Luck

by mc68h08

There are many new commands on XP command prompt to automate network administrators common tasks. You can switch off, set the registry, start jobs and a plethora of other interesting things on your windows network clients, but I want to suggest the new options of the old FOR command.

The old command FOR has in windows 2000 and XP many new options very useful to automate jobs.

I.E. the /R (recurse every subdir from a starting drive and path) or the /F can parse a text file and execute command using the tokens read from the files.

I have used the FOR in my batch files to scan some specific directories in a list of network clients, put these files together to generate a report of the activities of the users on my network.

For more references type "HELP FOR or FOR /?" in a command prompt.

I hope to have added something new to your knowledge,
Marco.

by camujtaba

No matter what version of DOS that you may work with, designing tools or utilities for data collection or manipulation requires some thought. What I suggest you start off with by identifying what is it that you need to accomplish. Once you know where you start and where you finish, the middle part will be easy to configure. A simple example: You want to run Mcafee Stinger on all your desktops as a secondary virus scan every SAT morning. Present the report in a html format.
Start: Drop stinger executable on all machines and create a batch file to run stinger in a silent mode. Rename the stinger log file to the hostname of your desktop. Once stinger is completed, copy log file to a central repository. Have another batch file that will sort infected machines from clean machines by reading log file data. Finally, append the proper html tag to name of your desktop and then join multiple files together to create your html file.

by swiley

You may want to take a look at using scripting (vbScript or Jscript). So many of the system components are now "open" to scripting, that you can do just about anything. I have created scripts to do most of the ?daily have tos? as a network administrator. Some these include creating DHCP reservations and dns entries, querying Active Directory and adding users. You will find that if you understand the concepts behind "batching", that you will have little or no problem with scripting. The big advantage to scripting would be that whole objects along with their properties are available to you.

A book that I have found very useful is Windows Admin Scripting, Second Edition Little Black Book (ISBN 1-932111-87-5). Also check out the Scripting Center at Microsoft, you will find many examples and other resource links. http://www.microsoft.com/technet/community/scriptcenter/default.mspx

I hope this is of use to you.

by oil patch

Hi Berin,

Redirection can be your friend. I recently discovered that redirecting to a file doesn't capture the errors. If you want to create a log file of your batch results, you need to redirect stderr to stdout, so you capture to your log file, any errors that occur. A quick google shows me that everyone else seemed to know this, but I just got it a few weeks ago.

$ SET_ETH0_PROP.BAT > C:\LOGS\LOGFILE.TXT
will create a new log file and put the output of the batch file in it, however, if any errors occur, they will still go to the screen

$ SET_ETH0_PROP.BAT > C:\LOGS\LOGFILE.TXT 2>&1
the "2>&1" includes the stderr into the stdout stream and puts any errors that occur in the log file.

MS kindly explains this at:
http://www.microsoft.com/windowsxp/home/using/productdoc/en/redirection.asp

Another command that turned out to be useful is START.

START "C: \ PROGRAM FILES \ SOMEPROG \ MYPROG.EXE"

Will kick off the program "myprog" in a separate process and continue on with your batch file with no waiting.

Cheers,
Patrick

by support

Dear Berin,

Today the scripting is popular again, because it is the tool for automation of the process. While in the Windows environment the person should usually monitor the process and is consulted for various answers, in batch processing you should have logging of the process, to be able to found the error in the process if necessary.

Task3000 was developed based on the experience of the batch on the host computer, and expanded with the Windows functionality. Maybe this is the tool you are looking for. It is great to see, how computers can perform your routine tasks automatically.

With best regards,
Miran

by mike_m

I administer a small LAN on NT4.0 server
I use batch files for practically every task.
Most useful, I would never change for anything using mouse, is a batch file where I have all users profile, passwords, etc.
I just can reload all profile in seconds. And it also is useful as history. I always have my floppy in my pocket.
Also, I use batch for setting all "at" tasks which I use for automating server tasks (temprary backup, antivirus update, sending messages to clients, sync some mirrors using xcopy etc, sending mail to externals when udating libraries etc).
I find much easier editing a batch file than adding a user profile or changing some setting using the mouse.
Mike

by br-tr

One way to learn more is use the command line help under XP. In a command window type help.
There are some really great extensions to the batch file in XP including an enhanced for command that allows one to create loops for directories, contents of files or even parsing the output of cammands, like Unix. As well, there are ways to pick out parts of an environment variable or batch file parameter, such as the file extension, file path etc.
Use help to get a list of the batch commands, then
help command_name
to get further details on command command_name

by tkalbas

Hello scripter,

The book that took my BATch scripts (still a necessary evil nowadays) to a higher level is, "Windows NT Shell Scripting", by Tim Hill, published by Macmillan Technical Publishing (MTP). In my 20+ years in the business, that's the most thorough book on the topic I've ever seen. And fairly current too.

I agree with the others that you should look into Windows Scripting Host. I've used it in automated scripts to, for example, read and write records to an Access database. Obviously, you can't do that from a BATch script without WSH! For interactive scripts, I've used WSH with the Internet Explorer object model to create a graphical user interface to a program that reads the contents of a CD-ROM, accepts runtime data entry from an operator, creates a mail-merge document in Word, and prints the document. All from a WSH script.

I couldn't have done all of the above without the following books:

Windows 2000 Windows Script Host, by Tim Hill
Windows Script Host Programmer's Reference, by Dino Esposito
Windows Script Host 2.0 Developer's Guide, by Gunter Born

And of course, you'll want to visit the Windows Script section on MSDN:

http://msdn.microsoft.com/library/default.asp?url=/nhp/default.asp?contentid=28001169

Happy scripting.

-- Tim

by jeckles

If you want to administer networking features from the command line you'll want to familiarize yourself with the following commands:
ipconfig (you probably already knew that one)
the net commands (type net help at the command prompt)
nbtstat for name resolution trouble shooting
netstat
netsh

There are lots more but these are some powerful tools to get you started

by damon.cruz

I've found WSH/VBScripting to be very powerful, but there are still some tricks that DOS can do well, like FTP (which can call its own scripting text files) and directory tree recursion with the For command. DOS also can 'get to work' without requiringe a lot of declarations and jazz. One plus for VBS is the ability to invoke a command shell or .exe and pass keystrokes.

I have several tasks that are solved with a mixture of both, but watch for issues like 'file in use' and environmentals as you create and use files or pass info between them.

by grsjr

Berin,
Another approach you may want to consider, particularly if you are in a mixed operating system environment, is the use of Unix/Linux style shell scripting tools. The Windows Services for Unix product or Motice Kern Systems (MKS) are two examples of powerful shell and scripting environments that run on Windows platforms and provide a very rich set of tools for batch processing, systems administration, and data processing.
I have used Windows Scripting and it is a very powerful and capable tool for the Windows platform. And while I have used both Windows and Unix/Linux operating systems for many years, the cross-over shell scripting tools provide for cross-platform management and a common set of tools/programs that function on a wide variety of systems. I have used these types of products in mixed and Windows-only environments myself and have saved considerable time and effort.
Anyway, another approach to consider in your quest for skills. Good luck!

by pd_smith

Berin,

I used to do lots of batch processing years ago.
The best source of tips & hints was the FIDONET
echomail called BATPOWER. A quick search revealed that some of the archives are still available. I
found the FAQ (with many tips/hints) at www.empowermentzone.com/batpower.txt

Hope this helps.

Peter Smith

by rdunn

Much of the data collection and manipulation that you refer to is easily accessible via scripting (as others have mentioned).

I don't believe that you can instantiate a WMI object through batch file scripting, so my suggestion is to check out http://www.microsoft.com/scripting for a start, and check out some of the tools available (scriptomatic comes to mind first).

VBScript/WSH can be used to output collected data into databases, simple text, and be manipulated to output into HTML (etc.).

Check it out - I'm sure you'll be quite impressed with the capability of VBScripting and WMI.

by bkarjala0001

I want to thank everyone who took time to submit a response. You should know that with their help I've been given a good foundation to stand on in my endeavor to Batch & Script. Also, special thanks to TechRepublic for providing us with an outlet for the technical community to propagate their knowledge. This has been a most positive experence for me, and I hope to contribute to others as others have helped me.

This discussion is closed to new replies.