In part 1 of our “Scripting Your Own Repair Tools” series, I showed you how to make use of applications to do tasks that the DOS commandline cannot do alone. In those examples, we gathered the computers CDKeys using the Nirsoft tool Produkey. In this article, I will be showing you a handful of useful applications that you can use to extend the functionality of your batch scripts.
Disclaimer: This article is for people with a good understanding of Windows only. I highly, HIGHLY recommend that you do scripting in either a Virtual Machine environment or a dedicated, unimportant machine in case you make a mistake with one of your commands and do some damage to the system. Technibble or I cannot be held responsible if you do damage to the operating system or lose any data.
Downloading Files with WGET
“WGET for Windows” is the Windows equivalent of the Unix-based wget command. Basically, this command will download a file from the URL you provide it. It supports FTPs, Proxies, password protected locations and more.
The typical usage for WGET would be:
wget http://nirsoft.net/utils/mailpv.zip
Zipping/Unzipping with 7Zip
7Zip is pretty well known compression tool amongst computer technicians, but did you know that it has a command line version as well?
You can download the command line version from here.
To make use of it, you can read about the available switches with some examples from this site. Here is an example of how to extract a zip file called mailpv.zip using the 7zip command line:
7za e mailpv.zip
You can also do opposite and make zip files. This example below will add the contents of the current users desktop. Then the zip file will be named whatever the current users username is:
7za a -tzip "%USERNAME%.zip" "%USERPROFILE%\Desktop"
Do Many Useful Tasks with NirCmd
NirCmd is a small command-line utility that allows you to do some useful tasks without displaying any user interface. NirCmd allows you to write and delete values and keys in the Registry, write values into INI file, dial to your internet account or connect to a VPN network, restart windows or shut down the computer, create shortcut to a file, change the created/modified date of a file, change your display settings, turn off your monitor, open the door of your CD-ROM drive, and more…
You can download NirCmd here and view the full help file containing the switches with some examples here.
Built-in DOS Commands
Since we are working with DOS batch scripts, pretty much any command that you would use with DOS will work in our batch scripts. Here is a site that has a large list of DOS commands you can make use of, including some examples.
You can also chain a bunch of DOS commands together and do some interesting things. For example, there is a command that allows you to change whether a service starts when Windows loads. With this command, you could create a script that turns off any unneeded services:
sc config RemoteRegistry start= DISABLED
sc config TabletInputService start= DISABLED
..and so on.
You could also reset the computers network settings with the following command:
ipconfig /release
ipconfig /flushdns
ipconfig /renew
Or even clear the systems Temporary Internet Files: (be careful)
attrib +a -s -h -r "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" /s
del /f /s /q "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*"
Then there is Robocopy. Robocopy is built into Windows Vista and Windows 7 and is a very powerful file management tool allowing you to perform advanced actions with files. For example, you could only copy files that have changed since the last backup. As you could imagine, this would be great for backup scripts. You can view Robocopy’s switches with some examples on this site.
You can also launch another batch file, from within the current batch file with the CALL command. You can use this to keep your code neat by having a Menu batch file and once the user selects a number, it calls the appropriate BAT file to do the task. This is how you would use it:
CALL BatchFile2.bat
Some Useful Applications That Support Command Line Use
You will be surprised of how many common applications have command-line versions and switches that you can make use of. Here are just a few:
There are many more commonly used repair tools that allow command line use. To find them, just type something like “SoftwareName command line” into a search engine.
That is all for part 4, dont forget to check out the scripting section of Technibbles forum. We have plenty of samples in there. In order to access it, you need to be a member of the forums for a little while and make good posts. We do this to prevent random search engine traffic from accessing them.
Session expired
Please log in again. The login page will open in a new tab. After logging in you can close it and return to this page.
Couple of suggestions..
CCleaner is a great tool as IMGBurn as is JZip..
However, the install for the full product installs extra stuff that you may or may not want..
CCLeaner will install the Yahoo! Toolbar
ImgBurn will add a toolbar set your homepage..
Jzip will also set your homepage
The point being, you have to be careful with the installation of these programs if you don’t want extra clutter…
If you don’t want the extra baggage for CCLeaner, go over to: http://www.piriform.com/ccleaner/builds
Grab either the Portable (no installer) or the Slim Editions..
ImGBurn, you have to watch each step of the install… You maybe able to do a custom install to get around the steps in question.
JZip, you have to watch each step of the install.. You maybe able to do a custom install to get around the steps in question.
Also, if you go over to http://www.appdeploy.com where you can learn a lot of the switches on how to install/unstall an application..
HTH,
Kent
One other option would be to use Ninite Pro. That would install the software without any of the extras and would only require you to script one software install command versus many.
The issue with Ninite is that the software that’s posted is usually not updated quickly enough to the latest versions. Sometimes it takes 4 to 6 days to see the latest version of an app. One example was with CCleaner where the latest version was available only after 4 days after it was posted on its official website. I end up getting it from ccleaner.com. This is not limited to ccleaner itself as I experienced the same problem with other software as well.
From one perspective it’s a great way for them to make sure that the software that was released is not broken. (How many time before we heard about a company releasing a software, but because of poor testing or whatnot, it broke things). From another perspective, if the latest version is available from manufacturer, it has to be available at Ninite.