Help TaskDefinition.Data property

Topics: Examples, Setup
Oct 11, 2016 at 2:23 AM
Was wondering if anyone knew how to set the data property and then retrieve it again from a created task.

Set TaskDefinition.Data to:
TEST
After task is created exported XML Data Node:
<![CDATA[0001000000ffffffff01000000000000000401000000e20153797374656d2e436f6c6c656374696f6e732e47656e657269632e44696374696f6e61727960325b5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d2c5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d5d040000000756657273696f6e08436f6d7061726572084861736853697a650d4b657956616c756550616972730003000308920153797374656d2e436f6c6c656374696f6e732e47656e657269632e47656e65726963457175616c697479436f6d706172657260315b5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d5d08e60153797374656d2e436f6c6c656374696f6e732e47656e657269632e4b657956616c75655061697260325b5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d2c5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d5d5b5d0200000009020000000300000009030000000402000000920153797374656d2e436f6c6c656374696f6e732e47656e657269632e47656e65726963457175616c697479436f6d706172657260315b5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d5d00000000070300000000010000000200000003e40153797374656d2e436f6c6c656374696f6e732e47656e657269632e4b657956616c75655061697260325b5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d2c5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d5d04fcffffffe40153797374656d2e436f6c6c656374696f6e732e47656e657269632e4b657956616c75655061697260325b5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d2c5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d5d02000000036b65790576616c75650101060500000004446174610606000000045445535401f9fffffffcffffff06080000000a416374696f6e547970650a0b]]>
When retrieving the Task.TaskDefinition.Data property again:
0001000000ffffffff01000000000000000401000000e20153797374656d2e436f6c6c656374696f6e732e47656e657269632e44696374696f6e61727960325b5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d2c5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d5d040000000756657273696f6e08436f6d7061726572084861736853697a650d4b657956616c756550616972730003000308920153797374656d2e436f6c6c656374696f6e732e47656e657269632e47656e65726963457175616c697479436f6d706172657260315b5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d5d08e60153797374656d2e436f6c6c656374696f6e732e47656e657269632e4b657956616c75655061697260325b5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d2c5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d5d5b5d0200000009020000000300000009030000000402000000920153797374656d2e436f6c6c656374696f6e732e47656e657269632e47656e65726963457175616c697479436f6d706172657260315b5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d5d00000000070300000000010000000200000003e40153797374656d2e436f6c6c656374696f6e732e47656e657269632e4b657956616c75655061697260325b5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d2c5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d5d04fcffffffe40153797374656d2e436f6c6c656374696f6e732e47656e657269632e4b657956616c75655061697260325b5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d2c5b53797374656d2e537472696e672c206d73636f726c69622c2056657273696f6e3d342e302e302e302c2043756c747572653d6e65757472616c2c205075626c69634b6579546f6b656e3d623737613563353631393334653038395d5d02000000036b65790576616c75650101060500000004446174610606000000045445535401f9fffffffcffffff06080000000a416374696f6e547970650a0b
I'm missing something, Any help is appreciated. Examples would be amazing!

Thanks

Joey
Oct 11, 2016 at 3:50 AM
Found msdn requirements, which was the cause of my problem.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa382552(v=vs.85).aspx

Requirements:
Minimum supported client - Windows Vista [desktop apps only]
Minimum supported server - Windows Server 2008 [desktop apps only]
Type library - Taskschd.tlb
DLL - Taskschd.dll


I changed the constuctor I used for TaskService to resolve the problem.

from:
using (TaskService ts = new TaskService(Environment.MachineName, null, null, null, true)) { ... }
to:
using (TaskService ts = new TaskService()) { ... }
Marked as answer by joeyzderadicka on 10/10/2016 at 7:50 PM
Coordinator
Oct 13, 2016 at 2:50 PM
You discovered the little secret behind wrapper compatibility between v1 and v2 -- I used the native Data property to store all the other properties that are missing in v1. Thus, when you look at the XML, you will see serialized data encoded for XML. When you use the library (under v1) you should see all the properties exactly as they were set.
Marked as answer by dahall on 10/13/2016 at 6:50 AM