I posted an example of a batch file sometime back. I have noticed some obvious errors that must have crept in when the forums were migrated
Have a look and adapt it to suit your environment