@ ECHO off
title BootMail
set debug=FALSE
set send=TRUE
set trace=TRUE
set bmrelease=2009 Aug 14
:: This is a "simple" Windows script (batch file) that can be set up to send an email every
:: time a computer boots up. It works on both XP and Vista, probably also Windows 7. It
:: serves these purposes: (1) To "phone home" if the computer is stolen and the thief is
:: stupid enough to just connect it to a network and boot it; (2) Provide a boot log of
:: sorts, perhaps for a computer that is offsite; and (3) Provide a check of the network
:: at bootup. The script looks like a big file but it's mostly comments.
:: BootMail should be run at bootup (system startup). It works entirely in the background
:: and may well phone home before the user or the thief logs on. It must be set up in the
:: Task Scheduler on Vista or Windows 7, so that it can have admin privileges, and it can
:: also be put in the Task Scheduler on XP. My Scheduled Tasks are set as follows:
:: * Run with the highest privileges (Vista, W7),
:: * Whether logged on or not,
:: * At startup (with 30-sec delay on Vista),
:: * Action is "start a program," pointing to this batch file,
:: * Start whether or not on battery (IMPORTANT if a laptop),
:: * In Vista Home Premium, under the Task Scheduler's General tab, if "Run whether user
:: is logged on or not" is checked, then "Do not store password" must also be checked,
:: to work around a Microsoft bug (Windows forgets the password anyway - DUH!).
:: The task name can be genuine or an obfuscation name.
:: The file containing this code should be named "whatever.cmd" where "whatever" can be an
:: obfuscation name. My file is currently called "bootmail.cmd" but I may decide to call
:: it something innocuous like "windowsscript.cmd." For sure the file extension must be
:: ".cmd" because that will cause the Task Scheduler to invoke the CMD.exe processor to
:: execute the file. It is not a .bat, or anything else but a .cmd batch file.
:: The script uses only standard Windows commands, except for the BLAT.exe command. BLAT
:: is a powerful command-line SMTP mailer for Windows, found here: http://www.blat.net
:: Unzip the download and copy the three files from the "full" sub-folder into a place
:: where CMD.exe will find them, such as c:\Windows\System32\. Run BLAT /? from a command
:: window to see the full functionality. BLAT can install some default values into the
:: registry if so requested, but that is not required and I chose not to. The result is a
:: very long command line for BLAT - see below.
:: On one computer running Windows XP Home Edition, the "SystemInfo.exe" command processor
:: did not exist. I copied that executable from another XP system into the system
:: directory on the Home Edition computer, and that works fine.
:: The email is sent in HTML format, so that columns will be lined up in the receiving
:: email client. This works OK in Windows Mail, Windows Live Mail, and Thunderbird. It
:: can be changed to plain text by deleting the "-html" option in the BLAT command, but
:: that alone will not significantly reduce the size of the email.
:: You will also need an email account that allows you to send email using SMTP. Both
:: GMAIL and GMX do allow this. I suggest GMX.com or GMX.us because they permit use of the
:: simplest SMTP protocol with standard port numbers.
:: FILES REQUIRED. All are created in the temporary directory %temp% and deleted on exit:
:: bootmail1.txt - Message body
:: bootmail2.txt - Scratch for editing command outputs
:: bootmail3.txt - Message subject
:: SWITCHES:
:: DEBUG: Set TRUE will cause this file to ECHO commands, not wait for the startup delay,
:: display the message body file, and pause after the mail is sent. With debug=TRUE you
:: can just click on bootmail.cmd and watch it run. You can also do that with
:: debug=FALSE but you will have to wait for the startup delay and you won't see much
:: on the screen.
:: SEND: Set FALSE to temporarily inhibit BLAT from actually sending the mail if you are
:: only debugging the content or format of the email message.
:: TRACE: Set FALSE to skip the TRACERT command and its associated delay.
:: TIMEOK: Internal. Programmatically set TRUE if the TIMEOUT command exists, else FALSE.
:: SITE-SPECIFIC CODE MODIFICATIONS:
:: You may want to change the following items in the code below:
:: * Owner, Phone, and email address (See the ECHO commands below).
:: * Target in the Tracert command. I chose my own ISP because tracert takes longer if
:: the path is longer. But you could use Google.com or MSN.com, whatever.
:: * In the BLAT.exe command, the -to parameter (your email address), -server (SMTP
:: server URL), -u (server logon name), -pw (server logon password), and -f (email
:: address of sender, which can be the same as -to address but need not be, although
:: it should be an address recognized by the SMTP server as belonging to the sender).
:: Disclaimer of liability: This software is provided "as is," and the developer makes no
:: warranty of merchantability or fitness. The developer may not be held liable for
:: damages of any sort, even if the software fails to function properly and even if the
:: developer is made aware of the possibiliy that damage could be caused. Your sole remedy
:: is a public apology. You may use this software only if you agree with this disclaimer.
:: The code begins here. Create the message-body file with the formatting tag for
:: columnar html, then insert the date and time:
PROMPT -:
IF /i %debug%==TRUE ECHO on
SET dateloc=%date%
SET timeloc=%time%
ECHO ^ > %temp%\bootmail1.txt
ECHO %computername% started %dateloc% %timeloc% >> %temp%\bootmail1.txt
:: If not debugging, wait for a couple of minutes here for the network to come up, and to
:: avoid competing with all of the other startup stuff. PING to a loopback address is a
:: clumsy way to create a delay, but it works in in all operating systems. Use TIMEOUT if
:: if it is available, though, because it probably consumes far less resources:
SET timeok=FALSE
TIMEOUT 1 && SET timeok=TRUE
IF /i %debug%==TRUE GOTO skipwait
IF /i NOT %timeok%==TRUE PING -n 121 127.0.0.1>nul
IF /i %timeok%==TRUE timeout 120
:skipwait
:: Insert the "proof of ownership" lines. Note: the command "ECHO." simply inserts a
:: blank line in the file:
ECHO. >> %temp%\bootmail1.txt
ECHO Owner: Mary Hanson >> %temp%\bootmail1.txt
ECHO Phone: 615-707-3278 >> %temp%\bootmail1.txt
ECHO email: marypdq@gmx.com >> %temp%\bootmail1.txt
:: Run SystemInfo and copy some interesting lines into the message body file:
ECHO. >> %temp%\bootmail1.txt
SYSTEMINFO.exe > %temp%\bootmail2.txt
FIND /i "Host Name:" < %temp%\bootmail2.txt >> %temp%\bootmail1.txt
FIND /i "OS Name:" < %temp%\bootmail2.txt >> %temp%\bootmail1.txt
FIND /i "OS Version:" < %temp%\bootmail2.txt >> %temp%\bootmail1.txt
FIND /i "Registered Owner:" < %temp%\bootmail2.txt >> %temp%\bootmail1.txt
FIND /i "Registered Organization:" < %temp%\bootmail2.txt >> %temp%\bootmail1.txt
FIND /i "Original Install Date:" < %temp%\bootmail2.txt >> %temp%\bootmail1.txt
FIND /i "System Model:" < %temp%\bootmail2.txt >> %temp%\bootmail1.txt
FIND /i "System Type:" < %temp%\bootmail2.txt >> %temp%\bootmail1.txt
FIND /i "Total Physical Memory:" < %temp%\bootmail2.txt >> %temp%\bootmail1.txt
FIND /i "Available Physical Memor" < %temp%\bootmail2.txt >> %temp%\bootmail1.txt
FIND /i "Domain:" < %temp%\bootmail2.txt >> %temp%\bootmail1.txt
FIND /i "Logon Server:" < %temp%\bootmail2.txt >> %temp%\bootmail1.txt
FIND /i "Hotfix(s):" < %temp%\bootmail2.txt >> %temp%\bootmail1.txt
DEL %temp%\bootmail2.txt
:: Include more stuff about the computer and the disk, from environment variables and
:: from FSUTIL:
ECHO. >> %temp%\bootmail1.txt
ECHO Home Path %homedrive%%homepath% >> %temp%\bootmail1.txt
ECHO Number of Processors %number_of_processors% >> %temp%\bootmail1.txt
ECHO Processor Identifier %processor_identifier% >> %temp%\bootmail1.txt
ECHO Processor Level %processor_level% >> %temp%\bootmail1.txt
ECHO Processor Revision %processor_revision% >> %temp%\bootmail1.txt
ECHO. >> %temp%\bootmail1.txt
ECHO System Root Drive %systemdrive% >> %temp%\bootmail1.txt
FSUTIL.exe volume diskfree %systemdrive% >> %temp%\bootmail1.txt
FSUTIL.exe dirty query %systemdrive% >> %temp%\bootmail1.txt
:: IPConfig shows a lot of stuff about the network configuration within the computer
:: as well as the DNS servers for the network:
ECHO. >> %temp%\bootmail1.txt
ECHO IPConfig /all: >> %temp%\bootmail1.txt
IPCONFIG.exe /all >> %temp%\bootmail1.txt
:: Tracert shows the exact network path from the (stolen?) computer to any target, in this
:: case qwest.net. You don't need to change this, because qwest.net is the end of the path
:: and you really only care about the beginning, but I prefer to make the target my ISP so
:: the whole path will be short - tracert needs a little time for each hop:
IF /i NOT %trace%==TRUE GOTO skiptrace
ECHO. >> %temp%\bootmail1.txt
ECHO tracert qwest.net: >> %temp%\bootmail1.txt
TRACERT.exe qwest.net >> %temp%\bootmail1.txt
:skiptrace
:: BootMail Release Date is the last line in the message body:
ECHO. >> %temp%\bootmail1.txt
ECHO BootMail Release Date %bmrelease% >> %temp%\bootmail1.txt
:: If debugging, display the whole message in the command window:
IF /i %debug%==TRUE TYPE %temp%\bootmail1.txt
:: Create the subject file, using the same time as in the message body:
ECHO %computername% up %dateloc% %timeloc% > %temp%\bootmail3.txt
:: Run BLAT to actually send the message. NOTE: This must be all one line, so you may
:: have to edit it a bit after copying it from the screen, making sure it really is
:: just one long line:
IF /i %send%==TRUE BLAT.exe %temp%\bootmail1.txt -to frankpdq@gmx.us -sf %temp%\bootmail3.txt -server mail.gmx.com -u marypdq@gmx.com -pw Obfusc8! -f marypdq@gmx.com -try 5 -html
:: Wait here if debug, scratch files still valid. Else delete the scratch files and quit:
IF /i %debug%==TRUE PAUSE
:: Remove the temporary files. Don't you wish everyone would?
del %temp%\bootmail1.txt
del %temp%\bootmail3.txt
:: End of script, end of batch file.