Batch File Programming

PREVIOUS     NEXT

Create Batch File to Start or End Window Services

 The windows environment can be easily changed by starting or ending various windows services. For example, this method can be used to easily shut down multiple services for a performance boost during game playing. Warning: Manipulating windows services can have unpredictable effects on your system. You should create a system restore point before experimenting. We all want to tweak or windows systems to the extreme to get the quickest, most powerful system possible. Many people will disable multiple window services manually before game playing. What a pain! Many times people forget what the services do or forget to restart the important ones. Services can be easily changed by creating batch files. The important commands are the following: NET START - starts the service NET STOP - ends the service For example: NET STOP "Error Reporting Service" Output: The Error Reporting Service service was stopped successfully. Knowing the commands, one can now easily create batch files calle... Read More

Supressing Prompts In Batch Files While Deleting All Files

 Successful batch files cannot be slowed down with a bunch of user prompts. This little recipe will show you how to supress prompts in batch files.Commands such as deleting all files can complicate batch files because the system prompts for confirmation. For example... del *.* replies with *.*, Are you sure (Y/N)? Man, that'll slow up a batch file. By using echo this will automatically reply for you: echo y| del *.* To supress the "File Not Found" error when trying to delete files from an empty directory, use this code instead: if exist *.* echo y| del *.*... Read More

Supress Responses From Commands In Batch Files

 This quick recipe describes how to supress responses to commands within batch files.During the execution of your batch files, users can see your commands on the screen. Most of the time this is good for debugging purposes; however, often it's better to run your batch file silently. Any command that is followed by "> nul" will not be shown on the screen. The greater sign directs the output to null (nowhere). For example, copy *.* *.bak will show you as it copies all the files in the directory and renames them with the bak extension. copy *.* *.bak > nul will silently complete its work without placing anything on the screen.... Read More

Processing the contents of a text file using FOR loop

 As admins, we often have to take actions against a list of things (computers, servers, file shares, etc). One great way to approach this is to put the list in a test file and use a FOR command to loop through the file and take a action against the contents.Say we have a file full of computernames: complist.txt: EricsPC BobsPC ExtraPC and we need to delete each of these computers from the domain. Using a FOR loop to profress the file is the way to go (especially if there are really 300 computer names!) First a test: FOR /f %a in ('complist.txt') do echo Computer: %a should return Computer: EricsPC Computer: BobsPC Computer: ExtraPC To actually delete the PCs from the domain, change the command to: FOR /f %a in ('complist.txt') do net computer \\%a /DEL When we run it we'll see net computer \\EricsPC /DEL net computer \\BobsPC /DEL net computer \\ExtraPC /DEL Of course we can use this to run any command-line against any list. In fact, we can use the FOR to run a command that would genera... Read More

Using variables in Windows batch files

 Regardless of the scripting language, the use of variables can greatly enhance the functionality of a script. This recipe demonstrated basic use of variables in MS-DOS or Windows batch files.The following script demonstrates a trivial example of setting a variable and displaying it: @echo off set var=testing 1 2 3 echo The variable is "%var%" If you put these lines in a file called test.bat and run this batch file by typing test from the command line in the same directory, you'll see the following output: The variable is "testing 1 2 3" You can view the defined system and user variables by typing set at the command line. You can use any of these variables in your batch files, for instance the variable %computername% contains the name of the system running the script. To unset or erase a previously set user variable, use the following command: set var= Variables, once set, can be used most anywhere in a batch file where text can go. For example, a variable can be set... Read More

 

 

Pages : 1