Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.


Need Batch File Ideas

  • Please log in to reply
2 replies to this topic

#1 pyromaniac4545


  • Members
  • 2 posts
  • Gender:Male
  • Location:Ohio
  • Local time:11:32 AM

Posted 08 June 2011 - 08:51 PM

Could some people give me some ideas on some batch files to make? I'm an amateur at them but I will be on a 3 hour car ride soon and would like to get better at them but I do not know what to make. Here is about what I can do so far.

@echo off

ECHO When do you want to shut down?
ECHO 1: 15 Minutes
ECHO 2: 30 Minutes
ECHO 3: 1 Hour
ECHO 4: 2 Hours
ECHO 5: 4 Hours
ECHO 6: 8 Hours
ECHO 7: 12 Hours
ECHO 8: 1 Day
ECHO 9: Restart Instead?

SET /P CHOICE=Choose a Option...

IF '%CHOICE%'=='1' SHUTDOWN -S -F -T 900
IF '%CHOICE%'=='2' SHUTDOWN -S -F -T 1800
IF '%CHOICE%'=='3' SHUTDOWN -S -F -T 3600
IF '%CHOICE%'=='4' SHUTDOWN -S -F -T 7200
IF '%CHOICE%'=='5' SHUTDOWN -S -F -T 14400
IF '%CHOICE%'=='6' SHUTDOWN -S -F -T 28800
IF '%CHOICE%'=='7' SHUTDOWN -S -F -T 43200
IF '%CHOICE%'=='8' SHUTDOWN -S -F -T 86400
IF '%CHOICE%'=='9' CALL Restart.bat



ECHO When do you want to restart?
ECHO 1: Now?
ECHO 2: 10 Minutes
ECHO 3: 20 Minutes
ECHO 4: 30 Minutes
ECHO 5: 45 Minutes
ECHO 6: 1 Hour
ECHO 7: 2 Hours
ECHO 8: 4 Hours
ECHO 9: 8 Hours

SET /P CHOICE=Choose a Option...

IF '%CHOICE%'=='1' SHUTDOWN -R -F -T 01
IF '%CHOICE%'=='2' SHUTDOWN -R -F -T 600
IF '%CHOICE%'=='3' SHUTDOWN -R -F -T 1200
IF '%CHOICE%'=='4' SHUTDOWN -R -F -T 1800
IF '%CHOICE%'=='5' SHUTDOWN -R -F -T 13500
IF '%CHOICE%'=='6' SHUTDOWN -R -F -T 3600
IF '%CHOICE%'=='7' SHUTDOWN -R -F -T 7200
IF '%CHOICE%'=='8' SHUTDOWN -R -F -T 14400
IF '%CHOICE%'=='9' SHUTDOWN -R -F -T 28800


BC AdBot (Login to Remove)


#2 JosiahK


  • Members
  • 269 posts
  • Gender:Male
  • Local time:04:32 PM

Posted 09 June 2011 - 04:33 AM

In batch (or anything to do with the Microsoft command line) it conventional to use the / character rather than the - character to mark out switches, but that shouldn't matter if they both work.

I can tell you one problem you'll have with that program.
The maximum delay you're allowed to set on a shutdown command is 600 (10 minutes).

I can't think of any task to try your hand at, and the common ones won't work as batch isn't really like any other language.
One command that is certainly worth getting your head around is for.
Other than that I'd just suggest finding things on your own computer that you'd like to automate. Perhaps have a go at reorganizing your music folder, creating backups, checking for old and unused files, etc. One little batch file I have places a hidden system folder called autorun.inf onto flash disks, a trick that prevents viruses from making an autorun.inf file in that location and therefore prevents them from infecting anything from my flash. It wasn't an exercise to teach myself batch files, but a tool to do something quickly which was previously taking several minutes each time.

PS Always test your script against a copy of your files, not the original. The best batch coder I know once left out a single line break in posting his script. That one change made the script delete every file and folder in the folder it was run from, deleting them as completely as if the recycle bin had then been emptied. You don't want that happening to your files.

Edited by JosiahK, 09 June 2011 - 04:33 AM.

Quod non mortiferum, fortiorem me facit.
I don't read minds. Please help everyone by answering any questions and reporting on the results of any instructions. Query any concerns and explain problems or complications.

#3 whoabuddy


    Bleepin' Verbose

  • Malware Response Instructor
  • 2,053 posts
  • Gender:Male
  • Location:Cottonwood, AZ
  • Local time:07:32 AM

Posted 15 June 2011 - 07:13 PM

Like Josiah said, the best function for batch files is automation. An easy way to find new things to create is to research how to do every day tasks from the command line and subsequently program them into a batch file. If you end up creating batch files that are related, you can use choice and call commands to build your logic. For example, I used to write batch files for login scripts and other functions on a corporate network, and one of the larger scripts I wrote helped with imaging and installing programs on a new PC. The logic worked something like this:

Main Menu
 Imaging Menu
  Machine Select
   Confirmation/Install, reboot
 Installation Menu
  Application List
   Install, return to app list
  Clean up desktop shortcuts

The fun and challenging part were in the little tweaks, learning about silent application installations and the switches you can use with the Windows Installer, trying to make it so that none of the functions interrupted the processing so I could let it run, and cleaning up the mess left by each program's installer. Another good command to look into is NETSH, which let you change a lot of settings related to your network connection. You can try creating a batch that changes your IP address, allowing you to choose between DHCP and Static, with some standard choices for static such as 192.168.0.x, 192.168.1.x, 192.168.2.x, etc. I use a script similar to this when DHCP isn't working on a network. You can also create a batch (or add a function to the IP one) that can enable/disable your Windows Firewall by choice.

Just be careful! I've always used SS64 as a command reference, they have some good info, and check out Sysinternals from Microsoft - they give you some awesome abilities from the command line!
Meditate. Elevate. Appreciate. | "Life is a journey, love is the destination, happiness is the path!"
If I am helping you and have not responded within 48 hours, please send me a PM.
Vi Veri Universum Vivus Vici (VVVVV)
Excellent Security Advice
Proud member of UNITE

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users