EDN Admin
Well-known member
Im trying to import an XML into Task Scheduler using VB, so far Ive gotten close (or at least I hope so) and have ended up with this as as my current output.
<pre class="prettyprint <?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>[/code]
currently, when I import this to Task Scheduler, I get the error
C:tests>schtasks /create /xml email.xml /tn testemail2<br/>
ERROR: The task XML is malformed.<br/>
(1,2)::
Whats wrong with my syntax?
Im using this VB script to write the XML, though, I dont think that its very prevalent... Also, it shouldnt matter what values it gets as long as theyre vaguely correct.
<pre class="prettyprint lang-vb 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[/code]
<br/>
View the full article
<pre class="prettyprint <?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>[/code]
currently, when I import this to Task Scheduler, I get the error
C:tests>schtasks /create /xml email.xml /tn testemail2<br/>
ERROR: The task XML is malformed.<br/>
(1,2)::
Whats wrong with my syntax?
Im using this VB script to write the XML, though, I dont think that its very prevalent... Also, it shouldnt matter what values it gets as long as theyre vaguely correct.
<pre class="prettyprint lang-vb 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[/code]
<br/>
View the full article