Link to home
Start Free TrialLog in
Avatar of mmchale
mmchale

asked on

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 = (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?
Avatar of TheMCSE
TheMCSE

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!
ASKER CERTIFIED SOLUTION
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial