This is the code that I used to test the Hidden attribute. I was unable to determine how to use Task Scheduler with the object names that are in your code above. The code below was developed using Visual Studio 2012 on a Windows 8 PC.
I found during my testing that the Hidden Attribute is not honored when
_TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN
is used in place
_TASK_LOGON_TYPE.TASK_LOGON_PASSWORD
when the task is registered.
public void CreateSchedule()
{
ITaskService ts =new TaskScheduler.TaskScheduler ();
ts.Connect();
ITaskDefinition td = ts.NewTask(0);
td.Settings.MultipleInstances = _TASK_INSTANCES_POLICY.TASK_INSTANCES_IGNORE_NEW ;
td.RegistrationInfo.Description = "working with network failOver";
td.Principal.LogonType = _TASK_LOGON_TYPE.TASK_LOGON_GROUP;
td.Settings.Hidden = true;
IDailyTrigger dt = (IDailyTrigger)td.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_DAILY);
dt.StartBoundary = DateTime.Now.AddMinutes(10).ToString("yyyy-MM-ddThh:mm:ss-06:00");
dt.DaysInterval = 2;
IExecAction action =(IExecAction) td.Actions.Create(_TASK_ACTION_TYPE.TASK_ACTION_EXEC);
action.Path = @"C:\windows\notepad.exe";
const string taskName = "TESTING Sync All Database";
ITaskFolder rootFolder = ts.GetFolder(@"\");
rootFolder.RegisterTaskDefinition(taskName,td,(int)_TASK_CREATION.TASK_CREATE_OR_UPDATE, "MyUsrName","MyPassword",_TASK_LOGON_TYPE.TASK_LOGON_PASSWORD );
while (System.Runtime.InteropServices.Marshal.ReleaseComObject(rootFolder) != 0)
{
Application.DoEvents();
}
rootFolder = null;
while (System.Runtime.InteropServices.Marshal.ReleaseComObject(dt) != 0)
{
Application.DoEvents();
}
dt = null;
while (System.Runtime.InteropServices.Marshal.ReleaseComObject(action) != 0)
{
Application.DoEvents();
}
action = null;
while (System.Runtime.InteropServices.Marshal.ReleaseComObject(td) != 0)
{
Application.DoEvents();
}
td = null;
while (System.Runtime.InteropServices.Marshal.ReleaseComObject(ts) != 0)
{
Application.DoEvents();
}
ts = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}