Importing XML into Task Scheduler

  • Thread starter Thread starter Zack1040
  • Start date Start date
Z

Zack1040

Guest
I'm trying to import an XML into Task Scheduler using VB, so far I've gotten close (or at least I hope so) and have ended up with this as as my current output.

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>22/09/2012 2:01:35 AM</Date>
<Author>Isaac</Author>
<Version>1.0.0</Version>
</RegistrationInfo>
<Triggers>
<EventTrigger>
<StartBoundary>2006-05-02T13:20:00</StartBoundary>
<EndBoundary>2700-05-02T13:20:00</EndBoundary>
<Subscription>
<QueryList>
<QueryId='1'>
<Select Path='System'>*[System/EventID=203]</Select>
</QueryId>
</QueryList>
</Subscription>
</EventTrigger>
</Triggers>
<Principals>
<Principal>
<UserId>Administrator</UserId>
<LogonType>InteractiveToken</LogonType>
</Principal>
</Principals>
<Settings>
<Enabled>true</Enabled>
<AllowStartOnDemand>true</AllowStartOnDemand>
<AllowHardTerminate>true</AllowHardTerminate>
</Settings>
<Actions>
<SendEmail>
<Server>127.0.0.1</Server>
<Subject>Task Failure</Subject>
<To>random_email@unknown.com</To>
<From>Client</From>
<Body>Error 203 occured, SyncToy might have problems.</Body>
</SendEmail>
</Actions>
</Task>

currently, when I import this to Task Scheduler, I get the error

C:\tests>schtasks /create /xml email.xml /tn testemail2
ERROR: The task XML is malformed.
(1,2)::


What's wrong with my syntax?


I'm using this VB script to write the XML, though, I don't think that its very prevalent... Also, it shouldn't matter what values it gets as long as they're vaguely correct.

Private Sub createNode(ByVal tdate As String, ByVal name As String, ByVal version As String, ByVal start As String, ByVal endbound As String, ByVal subt As String, _
ByVal user As String, ByVal logont As String, ByVal enabled As String, ByVal sod As String, ByVal aht As String, ByVal server As String, _
ByVal subject As String, ByVal sendto As String, ByVal sentfrom As String, ByVal body As String, ByVal writer As XmlTextWriter)

writer.WriteStartElement("RegistrationInfo")

writer.WriteStartElement("Date")
writer.WriteString(tdate)
writer.WriteEndElement()

writer.WriteStartElement("Author")
writer.WriteString(name)
writer.WriteEndElement()

writer.WriteStartElement("Version")
writer.WriteString(version)
writer.WriteEndElement()

writer.WriteEndElement()

writer.WriteStartElement("Triggers")

writer.WriteStartElement("EventTrigger")

writer.WriteStartElement("StartBoundary")
writer.WriteString(start)
writer.WriteEndElement()

writer.WriteStartElement("EndBoundary")
writer.WriteString(endbound)
writer.WriteEndElement()

writer.WriteStartElement("Subscription")
writer.WriteStartElement("QueryList")
writer.WriteStartElement("QueryId='1'")

writer.WriteStartElement("Select Path='System'")
writer.WriteString(subt)
writer.WriteEndElement()

writer.WriteEndElement()
writer.WriteEndElement()
writer.WriteEndElement()
writer.WriteEndElement()
writer.WriteEndElement()

writer.WriteStartElement("Principals")
writer.WriteStartElement("Principal")

writer.WriteStartElement("UserId")
writer.WriteString(user)
writer.WriteEndElement()

writer.WriteStartElement("LogonType")
writer.WriteString(logont)
writer.WriteEndElement()

writer.WriteEndElement()
writer.WriteEndElement()

writer.WriteStartElement("Settings")

writer.WriteStartElement("Enabled")
writer.WriteString(enabled)
writer.WriteEndElement()

writer.WriteStartElement("AllowStartOnDemand")
writer.WriteString(sod)
writer.WriteEndElement()

writer.WriteStartElement("AllowHardTerminate")
writer.WriteString(aht)
writer.WriteEndElement()

writer.WriteEndElement()

writer.WriteStartElement("Actions")

writer.WriteStartElement("SendEmail")
writer.WriteStartElement("Server")
writer.WriteString(server)
writer.WriteEndElement()

writer.WriteStartElement("Subject")
writer.WriteString(subject)
writer.WriteEndElement()

writer.WriteStartElement("To")
writer.WriteString(sendto)
writer.WriteEndElement()

writer.WriteStartElement("From")
writer.WriteString(sentfrom)
writer.WriteEndElement()

writer.WriteStartElement("Body")
writer.WriteString(body)
writer.WriteEndElement()
writer.WriteEndElement()
writer.WriteEndElement()
End Sub

Continue reading...
 
Back
Top