vbscript won't run from scheduled tasks

July 5, 2012 at 02:07:01
Specs: Windows XP
Good Afternoon,

I have this vbscript that sends an email through Lotus Notes whenever a file is generated inside a Windows folder. I had set it to run automatically on a daily basis through Windows Scheduled Tasks .

The Windows daily task is running successfully, but e-mails are not being received. When I run the vbscript manually emails are received successfully.

Would you know what could be the problem please?

Thanks for your help!

See More: vbscript wont run from scheduled tasks

Report •

July 5, 2012 at 07:17:31
What errors are you getting?

How To Ask Questions The Smart Way

Report •

July 5, 2012 at 13:45:30
No errors. The scheduled task (which is set to run the vbscript) is being automatically run successfully every day. However the trigger of the vbscript (i.e. sending an email through Lotus Notes) is not being done.

On the other hand, running the vbscript directly without involvement of the task scheduler triggers successfully the email.

Report •

July 5, 2012 at 18:28:05
Maybe post a copy of your vbscript, and the "at" commandline you are using to launch it into the schedule. If you can direct the output, (stdout) and the error output (stderr) generated by the mail-send command (not the vbscript itself, but the actual mail-send executed within the script) - to a logfile. They're probably being sent to the "at" process, and you need to see them.

Report •

Related Solutions

July 6, 2012 at 03:51:16
Hi nbrane, I'm copying my vbscript hereunder. I changed some things just for security/privacy purposes. However I don't understand the second part of your query. This is not being run by the commandline, but through Windows Scheduled Tasks.

Dim objFSO, objFolder
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists("\\test\error") Then
    Set objFolder = objFSO.GetFolder("\\test\error")
    If objFolder.Files.Count = 0 Then
        'MsgBox "The folder is empty"

    ' -------------------------------------------------------------------------- 
    ' -- Create Lotus Notes email (and add attachment) using VB Script 
    ' --  
    ' -- Version 1.01 
    ' -- 
    ' -- Created by : Michael Green 
    ' --              migreen@westpac.com.au 
    ' --  
    ' -- Based on in-complete/partially working script from : 
    ' -- <a href="http://en.allexperts.com/q/Using-Lotus-Notes-1427/Creating-LotusNotes-email-using-1.htm" target="_blank">http://en.allexperts.com/q/Using-Lo...</a> 
    ' -- 
    ' -- Created     : 06/10/2009 
    ' -- Last Updated: 07/10/2009 
    ' -------------------------------------------------------------------------- 
    Dim oSession        ' AS NotesSession 
    Dim strServer 
    Dim strUserName 
    Dim strMailDbName 
    Dim oCurrentMailDb  ' as NOTESDATABASE 
    Dim oMailDoc        ' as NOTESDOCUMENT 
    Dim ortItem         ' as NOTESRICHTEXTITEM 
    Dim ortAttacment    ' as NOTESRICHTEXTITEM 
    Dim oEmbedObject    ' as ???? 
    dim cstrAttachment 
    Dim blAttachment 
    'cstrAttachment = "c:\Temp\temp.txt" 
    'blAttachment = False 
    ' Start a session to notes 
    'wscript.echo "## Connecting to Lotus Notes session..." 
    Set oSession = CreateObject("Notes.NotesSession") 
    'wscript.echo("NotesVersion     : " & oSession.NotesVersion) 
    'wscript.echo("NotesBuildVersion: " & oSession.NotesBuildVersion) 
    'wscript.echo("UserName         : " & oSession.UserName) 
    'wscript.echo("EffectiveUserName: " & oSession.EffectiveUserName) 
    'wscript.echo "## GetEnvironmentString..." 
    strServer = oSession.GetEnvironmentString("MailServer",True) 
    'wscript.echo("Server           :" & strServer) 
    ' eg. CN=Michael V Green/OU=CORPAU/OU=WBCAU/O=WBG 
    strUserName = oSession.UserName 
    strMailDbName = Left(strUserName, 1) & Right(strUserName, (Len(strUserName) - InStr(1, strUserName, "")))&".nsf" 
    'wscript.echo("MailDbName        :" & strMailDbName) 
    'wscript.echo "## Getting current Notes database..." 
    ' open the mail database in Notes 
    set oCurrentMailDb = oSession.CurrentDatabase 
    'wscript.echo("fileName:" & oCurrentMailDb.fileName) 
    'wscript.echo("filePath:" & oCurrentMailDb.filePath) 
    'wscript.echo("server:" & oCurrentMailDb.server) 
    'wscript.echo("Title:" & oCurrentMailDb.Title) 
    If oCurrentMailDb.IsOpen = True Then 
        ' Already open for mail 
        'wscript.echo "## Lotus Notes mail database is already open !" 
        'wscript.echo "## Opening Lotus Notes mail database..." 
    End If 
    ' Create a document in the back end 
    Set oMailDoc = oCurrentMailDb.CREATEDOCUMENT 
    ' Set the form name to memo 
    OMailDoc.form = "Memo"  
    with oMailDoc 
        .SendTo = "123@123.com" 
        .CopyTo = "456@123.com, 789@123.com"  
        .Subject = "*****File/s is/are present in test folder*****"  
    end with 

    set ortItem = oMaildoc.CREATERICHTEXTITEM("Body") 
    with ortItem 
        .AppendText("Please handle file/s present in test folder") 
    End With 
    ' Create additional Rich Text item and attach it 
    If blAttachment Then 
        Set ortAttacment = oMailDoc.CREATERICHTEXTITEM("Attachment") 
        ' Function EMBEDOBJECT(ByVal TYPE As Short, ByVal CLASS As String, ByVal SOURCE As String, Optional ByVal OBJECTNAME As Object = Nothing) As Object 
        ' Member of lotus.NOTESRICHTEXTITEM 
        Set oEmbedObject = ortAttacment.EMBEDOBJECT(1454, "", cstrAttachment, "Attachment") 
    End If 
    'wscript.echo "## Sending email..." 
    with oMailDoc 
        .PostedDate = Now() 
        .SAVEMESSAGEONSEND = "True" 
    end with 
    'wscript.echo "## Sent !"  
    ' close objects 
    set oMailDoc       = nothing 
    set oCurrentMailDb = nothing 
    set oSession       = nothing

End If
End If

Report •

July 6, 2012 at 09:55:35
If I have to guess, and I'm going to have to because you disabled the output, never added any logging to the script, and you don't tell us the return code as reported by Scheduled Tasks, I'd say it's an issue with Lotus Notes. (Lotus Notes is not a good program.) Try running the script through Scheduled Tasks as whatever account you use on that machine. If that doesn't work, try running the script though Scheduled Tasks again, but this time have Notes open or closed, depending on if Notes was running before.

How To Ask Questions The Smart Way

Report •

July 12, 2012 at 05:40:32
Hi Razor,

Apologies for delay.

I tried running the script from Scheduled Tasks both with Lotus Notes open, and with Lotus Notes closed. Both failed.

Then I tried running the script directly (not from Scheduled Tasks), and it worked fine (i.e. e-mail was received). I think this eliminates any Lotus Notes issue.

The problem seems to come from Scheduled Tasks, however the task is running successfully on a daily basis; it's just that the e-mail is not being triggered for some reason or another.

Report •

July 12, 2012 at 05:41:50
Please note that until some time ago it used to work fine even from Scheduled Tasks. I noted that it was not working when I tried to run it for testing purposes during these last days.

Report •

Ask Question