Scheduling a Batch File to Email when Windows 2000 Boots
30 November -0001
by Justin
November 20, 2003
I recently had the interesting challenge of figuring out a way to have the Windows 2000 machines in a network email me when they rebooted. I wanted to use a batch file so I wouldn't have to compile or install anything as well.
The first challenge was to find a suitable mail server. I had a real Sendmail mail server available, but couldn't figure out a way to get email to that server via a batch file. Eventually I settled on using the default SMTP server available with IIS. If you do this be sure to limit relays on the SMTP server to only relay email from 127.0.0.1 so you don't have to worry about your server becoming a spam relay.
Once you've got the SMTP server up and running all you need to do is get a file into C:\Inetpub\mailroot\Pickup and the server will relay the file (with a .eml extension) off as an email. I set up the Pickup folder on the SMTP server to be shared so I could drop emails into it from any other machine on the network.
Next I went to each computer that would be sending the startup email and mapped a network drive to the Pickup folder (usually this ended up being mapped to the I: drive). To do this open up 'My Computer' and click on the Tools menu, then choose 'Map Network Drive' and navigate to the shared folder. Make sure that you leave the 'Reconnect' checkbox checked so the mapped drive will be there when the computer reboots.
To create the batch file open up notepad and drop this in:
@echo off Echo X-Sender: MachineThatIsStarting>%temp%\file.eml Echo X-Receiver: youremail@yourdomain.tld>>%temp%\file.eml Echo From: MachineThatIsStarting>>%temp%\file.eml Echo To: youremail@yourdomain.tld>>%temp%\file.eml Echo Subject: MachineThatIsStarting rebooted>>%temp%\file.eml Echo Content-Type: text/plain;>>%temp%\file.eml Echo.>>%temp%\file.eml Echo MachineThatIsStarting booted up successfully at %date% %time%.>>%temp%\file.eml Move %temp%\file.eml I:\
and save it as "bootemail.bat", make sure to include the quotes around the file name so Notepad doesn't save the file as a text file.
Then schedule a task to run the batch file on bootup. You might want to test the batch file by running it via command line first however. To schedule a task go to your Start menu, select Programs, then Accessories, then System Tools then Schedule Task. Create a new scheduled task and use the 'Browse' button to browse to the 'bootemail.bat' file and make sure you schedule it to run when the computer boots (now when someone logs on). After that you should be good to go.