- Batch Script Tutorial
I try to create a batch file to run under Windos XP in a command window (or just double clicking the BAT file). The intention is to take all files with a given extension, concatenate them and add some extra information 'between the files'. To do this, I need to add a counter value like 1 for the first file, 2 for the second and so on. You can add switches to your script for different options, such as: /delete - to delete a mapped drive /persistent:yes/no - to reconnect the drive upon login. I personally leave it the way it is and just add one more line: del.bat. This way, I drop it in a user's startup folder and it will run once and that's it. Edit the batch file's contents. At any time, you can right-click your batch file and click Edit in the resulting drop-down menu. This will open the batch file as a Notepad document; at this point, you can make any changes and then save the file by pressing Ctrl+S. The changes will immediately be reflected when you run the batch file. Type the name of the batch file. For example, if it’s called “program.bat,” type program.bat. If you don’t know the name, type dir and press ↵ Enter to view the files in the folder. You’ll find it there.
- Batch Script Resources
- Selected Reading
BAT File (What It Is And How To Open One)
Adding to the registry is done via the REG ADD command. Note that in order to add values to the registry you need to have sufficient privileges on the system to perform this operation.
Syntax
The REG ADD command has the following variations. In the second variation, no name is specified for the key and it will add the name of “(Default)” for the key.
Where
- ValueName − The value, under the selected RegKey, to edit.
- /d Data − The actual data to store as a 'String', integer, etc.
- /f − Force an update without prompting 'Value exists, overwrite Y/N'.
- /S Separator − Character to use as the separator in REG_MULTI_SZ values. The default is '0'.
- /t DataType − These are the data types defined as per the registry standards which can be −
- REG_SZ (default)
- REG_DWORD
- REG_EXPAND_SZ
- REG_MULTI_SZ
Batch File Add Date Time To Filename
Example
In the above example, the first part is to add a key into the registry under the location HKEY_CURRENT_USERConsole. This key will have a name of Test and the value assigned to the key will be Test Data which will be of the default string type.
The second command just displays what was added to the registry by using the REG QUERY command.
Output
Following will be the output of the above program. The first line of the output shows that the ‘Add’ functionality was successful and the second output shows the inserted value into the registry.