We’ve all heard of the utterly useful batch files. Dreaded as they are, some batch file tricks can automate a lot of tasks and in the process, provide some really interesting (or annoying) scares and laughs.
In essence, a batch file offers all that you can achieve with the command line. In addition however, it also allows a couple more features; including the use of variables and the conditional statements (if-else). Here are a few batch file tricks:
The shutdown command when used within a batch file can perform a lot of powerful actions. If you feel shutting down your machine requires more clicks than necessary, you can create desktop shortcut for the same. Here are the various parameters available:
/s – shutdown
/h – hibernate
/r – restart
/a – abort a shutdown command
/p – shutdown without warnings
/t – specifies the time in seconds after with the machine shuts down. The default time for shutdown is 30 seconds
/m – shuts down a remote computer on the network
Write the following line in notepad and save it with name ‘shutdown.bat’. Whenever you open this ‘shutdown.bat’ file, windows will shutdown after 120 seconds.
(Also works when this code is directly entered in Command Prompt/cmd)
shutdown /s /t 120
The /m attribute allows you to shut down a machine on the network. This can serve as a clever way for spreading scare on a network. It is to be noted however that the target machine should support remote shutdown. Following code shutsdown a windows system(188.8.131.52) in network after 120 seconds.
shutdown /s /t 120 /m 184.108.40.206
To abort shutdown, use the following code and save it as ‘abort.bat’. But this code must be executed within time(120secs).
For this batch file trick, it is advisable to make two shortcuts one each for shutting down and for aborting an accidental command.
To check if its working fine, open your ‘shutdown.bat’ file and once countdown for shutdown starts, run ‘abort.bat’. Shutdown would stop.
Make a harmless virus for automatic shutdown
The commands given below create a small, harmless virus that forces the shutdown of the machine. The commands develop an infinite loop. The only way to stop the unfolding windows is to either find out the parent window and close it, or restart the machine.
:start start name.bat go to start
Here ‘name.bat’ is the name of the file you save these commands in(again, as ‘shutdown.bat’).
This simple loop opens the file and keeps repeating the operation due to the ‘go to start’. line.
And here is one cool batch file trick,
Run CMD and Regedit when blocked
If your administrator has blocked CMD and/or the Registry, here’s a way to circumvent it.
- Open notepad and enter ‘COMMAND.COM'(for CMD) or ‘Start regedit'(for Registry)
- Save the file as ‘anything.bat’ (without the quotes)