
                    td.Settings.DisallowStartIfOnBatteries = false;
                    td.Settings.StopIfGoingOnBatteries = false;

                    // Register the task in the root folder
                    ts.RootFolder.RegisterTaskDefinition(theName, td);
                }
                catch (UnauthorizedAccessException ex)