Пример #1
0
 /// <summary>
 /// Releases the unmanaged resources used by the <see cref="T:System.ComponentModel.Component"/> and optionally releases the managed resources.
 /// </summary>
 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
 protected override void Dispose(bool disposing)
 {
     if (v2TaskService != null)
     {
         try
         {
             Marshal.ReleaseComObject(v2TaskService);
         }
         catch { }
         v2TaskService = null;
     }
     if (v1TaskScheduler != null)
     {
         try
         {
             Marshal.ReleaseComObject(v1TaskScheduler);
         }
         catch { }
         v1TaskScheduler = null;
     }
     if (v1Impersonation != null)
     {
         v1Impersonation.Dispose();
         v1Impersonation = null;
     }
     base.Dispose(disposing);
 }
Пример #2
0
        internal static V1Interop.ITask GetTask(V1Interop.ITaskScheduler iSvc, string name)
        {
            Guid ITaskGuid = Marshal.GenerateGuidForType(typeof(V1Interop.ITask));

            try { return(iSvc.Activate(name, ref ITaskGuid)); } catch {}
            return(null);
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskService"/> class.
 /// </summary>
 /// <param name="targetServer">The target server. A null value implies the local machine.</param>
 /// <param name="userName">Name of the user.</param>
 /// <param name="accountDomain">The account domain.</param>
 /// <param name="password">The password.</param>
 /// <param name="forceV1">If set to <c>true</c> force Task Scheduler 1.0 compatibility.</param>
 public TaskService(string targetServer, string userName, string accountDomain, string password, bool forceV1)
 {
     if (hasV2 && !forceV1)
     {
         v2 = true;
         v2TaskService = new V2Interop.TaskSchedulerClass();
         if (!string.IsNullOrEmpty(targetServer))
         {
             // Check to ensure character only server name. (Suggested by bigsan)
             if (targetServer.StartsWith(@"\"))
                 targetServer = targetServer.TrimStart('\\');
             // Make sure null is provided for local machine to compensate for a native library oddity (Found by ctrollen)
             if (targetServer.Equals(Environment.MachineName, StringComparison.CurrentCultureIgnoreCase))
                 targetServer = null;
         }
         v2TaskService.Connect(targetServer, userName, accountDomain, password);
     }
     else
     {
         v1Impersonation = new WindowsImpersonatedIdentity(userName, accountDomain, password);
         V1Interop.CTaskScheduler csched = new V1Interop.CTaskScheduler();
         v1TaskScheduler = (V1Interop.ITaskScheduler)csched;
         if (!string.IsNullOrEmpty(targetServer))
         {
             // Check to ensure UNC format for server name. (Suggested by bigsan)
             if (!targetServer.StartsWith(@"\\"))
                 targetServer = @"\\" + targetServer;
             v1TaskScheduler.SetTargetComputer(targetServer);
         }
     }
 }
Пример #4
0
        /// <summary>
        /// Connects this instance of the <see cref="TaskService"/> class to a running Task Scheduler.
        /// </summary>
        private void Connect()
        {
            ResetUnsetProperties();

            if (!initializing && !DesignMode &&
                ((!string.IsNullOrEmpty(userDomain) && !string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(userPassword)) ||
                 (string.IsNullOrEmpty(userDomain) && string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(userPassword))))
            {
                // Clear stuff if already connected
                if (this.v2TaskService != null || this.v1TaskScheduler != null)
                {
                    this.Dispose(true);
                }

                if (hasV2 && !forceV1)
                {
                    v2TaskService = new V2Interop.TaskSchedulerClass();
                    if (!string.IsNullOrEmpty(targetServer))
                    {
                        // Check to ensure character only server name. (Suggested by bigsan)
                        if (targetServer.StartsWith(@"\"))
                        {
                            targetServer = targetServer.TrimStart('\\');
                        }
                        // Make sure null is provided for local machine to compensate for a native library oddity (Found by ctrollen)
                        if (targetServer.Equals(Environment.MachineName, StringComparison.CurrentCultureIgnoreCase))
                        {
                            targetServer = null;
                        }
                    }
                    v2TaskService.Connect(targetServer, userName, userDomain, userPassword);
                    targetServer = v2TaskService.TargetServer;
                    userName     = v2TaskService.ConnectedUser;
                    userDomain   = v2TaskService.ConnectedDomain;
                    maxVer       = GetV2Version();
                }
                else
                {
                    v1Impersonation = new WindowsImpersonatedIdentity(userName, userDomain, userPassword);
                    V1Interop.CTaskScheduler csched = new V1Interop.CTaskScheduler();
                    v1TaskScheduler = (V1Interop.ITaskScheduler)csched;
                    if (!string.IsNullOrEmpty(targetServer))
                    {
                        // Check to ensure UNC format for server name. (Suggested by bigsan)
                        if (!targetServer.StartsWith(@"\\"))
                        {
                            targetServer = @"\\" + targetServer;
                        }
                    }
                    else
                    {
                        targetServer = null;
                    }
                    v1TaskScheduler.SetTargetComputer(targetServer);
                    targetServer = v1TaskScheduler.GetTargetComputer();
                    maxVer       = v1Ver;
                }
            }
        }
Пример #5
0
 /// <summary>
 /// Releases all resources used by this class.
 /// </summary>
 public void Dispose()
 {
     if (wienum != null)
     {
         Marshal.ReleaseComObject(wienum);
     }
     m_ts = null;
 }
Пример #6
0
 /// <summary>
 /// Releases all resources used by this class.
 /// </summary>
 public void Dispose()
 {
     if (v2Folder != null)
     {
         System.Runtime.InteropServices.Marshal.ReleaseComObject(v2Folder);
     }
     v1List = null;
 }
Пример #7
0
 /// <summary>
 /// Releases all resources used by this class.
 /// </summary>
 public void Dispose()
 {
     v1TS = null;
     if (v2Coll != null)
     {
         Marshal.ReleaseComObject(v2Coll);
     }
 }
Пример #8
0
 /// <summary>
 /// Internal constructor
 /// </summary>
 /// <param name="svc">TaskService instance</param>
 /// <param name="filter">The filter.</param>
 internal V1TaskEnumerator(TaskService svc, Regex filter = null)
 {
     this.svc    = svc;
     this.filter = filter;
     m_ts        = svc.v1TaskScheduler;
     wienum      = m_ts.Enum();
     Reset();
 }
 internal static V1Interop.ITask GetTask(V1Interop.ITaskScheduler iSvc, string name)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException("name");
     }
     try
     {
         return(iSvc.Activate(name, ref ITaskGuid));
     }
     catch (System.UnauthorizedAccessException)
     {
         // TODO: Take ownership of the file and try again
         throw;
     }
     catch (System.ArgumentException)
     {
         return(iSvc.Activate(name + ".job", ref ITaskGuid));
     }
     catch { throw; }
 }
Пример #10
0
 internal static V1Interop.ITask GetTask([NotNull] V1Interop.ITaskScheduler iSvc, [NotNull] string name)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException(nameof(name));
     }
     try
     {
         return(iSvc.Activate(name, IID_ITask));
     }
     catch (UnauthorizedAccessException)
     {
         // TODO: Take ownership of the file and try again
         throw;
     }
     catch (ArgumentException)
     {
         return(iSvc.Activate(name + ".job", IID_ITask));
     }
     catch (FileNotFoundException)
     {
         return(null);
     }
 }
Пример #11
0
 /// <summary>
 /// Releases all resources used by this class.
 /// </summary>
 public void Dispose()
 {
     if (v2Folder != null)
         System.Runtime.InteropServices.Marshal.ReleaseComObject(v2Folder);
     v1List = null;
 }
Пример #12
0
 internal TaskFolder(TaskService svc)
 {
     this.TaskService = svc;
     v1List = svc.v1TaskScheduler;
 }
Пример #13
0
        /// <summary>
        /// Connects this instance of the <see cref="TaskService"/> class to a running Task Scheduler.
        /// </summary>
        private void Connect()
        {
            ResetUnsetProperties();

            if (!initializing && !DesignMode &&
                ((!string.IsNullOrEmpty(userDomain) && !string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(userPassword)) ||
                (string.IsNullOrEmpty(userDomain) && string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(userPassword))))
            {
                // Clear stuff if already connected
                if (this.v2TaskService != null || this.v1TaskScheduler != null)
                    this.Dispose(true);

                if (hasV2 && !forceV1)
                {
                    v2TaskService = new V2Interop.TaskSchedulerClass();
                    if (!string.IsNullOrEmpty(targetServer))
                    {
                        // Check to ensure character only server name. (Suggested by bigsan)
                        if (targetServer.StartsWith(@"\"))
                            targetServer = targetServer.TrimStart('\\');
                        // Make sure null is provided for local machine to compensate for a native library oddity (Found by ctrollen)
                        if (targetServer.Equals(Environment.MachineName, StringComparison.CurrentCultureIgnoreCase))
                            targetServer = null;
                    }
                    v2TaskService.Connect(targetServer, userName, userDomain, userPassword);
                    targetServer = v2TaskService.TargetServer;
                    userName = v2TaskService.ConnectedUser;
                    userDomain = v2TaskService.ConnectedDomain;
                    maxVer = GetV2Version();
                }
                else
                {
                    v1Impersonation = new WindowsImpersonatedIdentity(userName, userDomain, userPassword);
                    V1Interop.CTaskScheduler csched = new V1Interop.CTaskScheduler();
                    v1TaskScheduler = (V1Interop.ITaskScheduler)csched;
                    if (!string.IsNullOrEmpty(targetServer))
                    {
                        // Check to ensure UNC format for server name. (Suggested by bigsan)
                        if (!targetServer.StartsWith(@"\\"))
                            targetServer = @"\\" + targetServer;
                    }
                    else
                        targetServer = null;
                    v1TaskScheduler.SetTargetComputer(targetServer);
                    targetServer = v1TaskScheduler.GetTargetComputer();
                    maxVer = v1Ver;
                }
            }
        }
Пример #14
0
 internal RunningTaskCollection(TaskService svc)
 {
     this.svc = svc;
     v1TS     = svc.v1TaskScheduler;
 }
Пример #15
0
 internal TaskFolder(TaskService svc)
 {
     this.TaskService = svc;
     v1List           = svc.v1TaskScheduler;
 }
Пример #16
0
 internal TaskCollection(TaskService svc, Regex filter = null)
 {
     this.svc    = svc;
     this.Filter = filter;
     v1TS        = svc.v1TaskScheduler;
 }
Пример #17
0
 /// <summary>
 /// Releases the unmanaged resources used by the <see cref="T:System.ComponentModel.Component"/> and optionally releases the managed resources.
 /// </summary>
 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
 protected override void Dispose(bool disposing)
 {
     if (v2TaskService != null)
     {
         Marshal.ReleaseComObject(v2TaskService);
         v2TaskService = null;
     }
     if (v1TaskScheduler != null)
     {
         Marshal.ReleaseComObject(v1TaskScheduler);
         v1TaskScheduler = null;
     }
     if (v1Impersonation != null)
     {
         v1Impersonation.Dispose();
         v1Impersonation = null;
     }
     base.Dispose(disposing);
 }