Send email as scheduled task using vbscript on Windows XP

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 = (

Set objEmail = CreateObject("CDO.Message")

' Assign message properties (To, From, Subject, etc.)
objEmail.From = ""
objEmail.To = "testuser@cpaw"
objEmail.Subject = "Sync email file"
objEmail.Textbody = "Sync files attached"
objEmail.Configuration.Fields.Item ("") = _

objEmail.AddAttachment AttachFile

' Assign additional message properties, update the object, and send the message
objEmail.Configuration.Fields.Item ("") = 2
objEmail.Configuration.Fields.Item ("") = 25

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
Computer: CHV0DTXP0011
Access denied attempting to launch a DCOM Server. The server is:
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?
Who is Participating?
Robberbaron (robr)Connect With a Mentor Commented:
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

        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
                                    errptr = 5

              .Host = ""
              .From = ""
              .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
            End With

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!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.