if file.txt is old start progr.exe & email me

March 18, 2011 at 12:32:59
Specs: Windows 7
Hi guys,
I'm not good with batch files, so pls pseudocode your answers. I need a script that every X minutes checks if a file.txt has been updated. If file.txt has not been updated the script should start progr.exe

Ideally, I would also like the script to send me an email with file.txt in attachment

so far this is what I have:

@echo off

if not exist file.txt (ping -n 180 localhost >nul
goto loop)

start progr.exe

See More: if file.txt is old start progr.exe & email me

Report •

March 20, 2011 at 16:33:43
Hello ..Try this.. i guess this is what exactly you want.


@echo off
type %0 | find " " | findstr /v "UMMmmmm" >%temp%\sendemail.vbs

::replace C:\test.txt with your actual file in next line...
set file=C:\test.txt

dir /b /aa %file% >nul
if %errorlevel% == 0 (
echo The file has changed since last check..
echo. Sending notification email..
cscript /nologo %temp%\sendemail.vbs
echo. Email notification sent ...
echo. Changing archive bit ....
attrib -a %file%
echo Waiting for 5 seconds to check again..
if %errorlevel% == 1 echo File has not been changed yet.

ping -n 5 >nul
goto start

goto :EOF

SMTPServer = "blabl.blah.com"
Recipient = "blah@blah.com"
From = "blah@blah.com"
Subject = "Test email"
Message = "This is test emalis,you can change the subject "

attachment = "c:\test.txt"

GenericSendmail SMTPserver, From, Recipient, Subject, Message

Sub GenericSendmail (SMTPserver, From, Recipient, Subject, Message)

set msg = WScript.CreateObject("CDO.Message")
msg.From = From
msg.To = Recipient
msg.Subject = Subject
msg.TextBody = Message
msg.AddAttachment attachment

msg.Configuration.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2



End Sub


The formating may get messed up in this box so you may download the bat directly from below weblink..


make sure to modify these feilds in the batch..

set file=C:\test.txt
attachment = "c:\test.txt" to your original file url

SMTPServer = "blabl.blah.com"
Recipient = "blah@blah.com"
From = "blah@blah.com"
Subject = "Test email"

DO note that there are spaces before vb codes, if you remove them it will not work..

Subhash Chandra.

Report •

March 21, 2011 at 05:24:25
Thanks Subhash,
It seems exactly what I need, I'll try to implement this code over the weekend and postback if something will not be clear.
Great Job!

Report •

March 22, 2011 at 13:17:10
Hi there,
I was trying this code and I got stuck again with an error message saying:

"C:\Users\michele\AppData\Local\Temp\sendemail.vbs(18, 9) (null): The server reje
cted the sender address. The server response was: 530 5.7.0 No AUTH command has been given."

Any idea how to fix this? Thanks!

Report •

Related Solutions

March 23, 2011 at 14:58:08
this is the SMTP servers response ..Depends on which Server u r using as your SMTP one..GMail will not work or similer

Subhash Chandra.

Report •

Ask Question