[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Send email as scheduled task using vbscript on Windows XP

Posted on 2005-04-26
4
Medium Priority
?
6,285 Views
Last Modified: 2010-05-18
I have a VBscript that will enumerate the file name in a specific folder, set it as a variable, then send it as an attachment in an email.  

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService. _
    ExecQuery("Select * from CIM_DataFile where Path = '\\syncout\\'")

For Each objFile in colFiles
  attachFile = (objfile.name)
Next

Set objEmail = CreateObject("CDO.Message")

' Assign message properties (To, From, Subject, etc.)
objEmail.From = "Project_Team@cpaw.com"
objEmail.To = "testuser@cpaw"
objEmail.Subject = "Sync email file"
objEmail.Textbody = "Sync files attached"
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
 "cvntex04"

'Attachment(s)
objEmail.AddAttachment AttachFile


' Assign additional message properties, update the object, and send the message
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send


This needs to be done twice per day.  I'm currently running it as a scheduled task on a Windows XP (SP1) box.  It works fine as long as the user (Local admin) account is logged in.  Once logged off the scheduled task fails and the following error is recorded in the event log:

Event Type: Error
Event Source: DCOM
Event Category: None
Event ID: 10002
Date:  4/22/2005
Time:  3:45:02 PM
User:  NT AUTHORITY\SYSTEM
Computer: CHV0DTXP0011
Description:
Access denied attempting to launch a DCOM Server. The server is:
{05D1D5D8-18D1-4B83-85ED-A0F99D53C885}
The user is SYSTEM/NT AUTHORITY, SID=S-1-5-18.

The server 05D1D5D8-18D1-4B83-85ED-A0F99D53C885} shows in the registry as CCM WMI Event Provider.  I imagine it's a permissions issue with the WMI service or DCOM. I've tried changing some permissions for both but nothing has worked so far. Ideas?
0
Comment
Question by:mmchale
2 Comments
 
LVL 7

Expert Comment

by:TheMCSE
ID: 13892160
This sounds like a DCOM permissions issue for sure.  Who is the scheduled task running as?  Since it shows System, it makes me think that you may have used at.exe to schedule this?  It may be easier to just ensure that the scheduled job is running as the local admin.  Good luck!
0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 2000 total points
ID: 13903788
I think the CDO is MAPI based which generally needs a loged in user. At least when i tried it did.

I gave up and used an SMTP mail method.   using MailSender Dll  
[[ not sure it handles attachments in free version ]]

'====REQUIRES ---
' Free ASPEmail 4.2  http://www.aspemail.com/
'==============

        'ibset.MoveFirst
        Dim oEmail As MailSender
        Set oEmail = New MailSender    'create email object
        errptr = 2
        Dim testvar As Variant
        evtcount = 0: evtoverdue = 0
        Do While Not ibset.EOF

          'check for reminders on for relevant staff
            Dim msg As String, msg_title As String
                     
            'compose message
                   
            msg_title = "Info Event Reminder : " & ibset.Fields("etd")
            MsgAdd msg, "Event type : " & ibset.Fields("etd")
   
            'add all the info to the message
            With oEmail
              .Reset
                                    errptr = 5

              .Host = "mailman.bw.firm.au"
              .From = "Infobase@bornhorstward.com.au"
              .FromName = "InfoBase"
              .IsHTML = False
             
              .Priority = msgpriority
             
              'set the subject
              .Subject = msg_title

              mailrecip = ibset.Fields("emailint")

              .AddAddress mailrecip, tmp  '"Info user"
              'set the text
              .Body = msg
       
                'here's where we'd actually send it
                .Send
            End With

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question