Quantcast
Viewing all articles
Browse latest Browse all 2206

New Post: how to use a Group Managed service account to run a schedule task and make it "Run whether user is logged on or not"?

these tow ways are not working, here is my test code, I test it on windows server 2012R2:
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32.TaskScheduler;

namespace WrapperDemo
{
    internal static class Program
    {
        public static void Main(string[] args)
        {
            try
            {
                var action = new ExecAction(@"C:\PowerSlim\test.cmd");
                var trigger = new DailyTrigger(1);
                trigger.StartBoundary = DateTime.Today.AddHours(20);
                TaskService.Instance.AddTask("msaTask", trigger, action, @"er\zz$", "", TaskLogonType.Password);
            }
            catch (COMException exception)
            {
                Console.WriteLine(exception.ToString());
            }

        }
    }
}
I got exception like following on the console output:

System.Runtime.InteropServices.COMException (0x8007052E): The username or password is incorrect. (Exception from HRESULT: 0x8007052E)
at Microsoft.Win32.TaskScheduler.V2Interop.ITaskFolder.RegisterTaskDefinition(String Path, ITaskDefinition pDefinition, Int32 flags, Object UserId, Object password, TaskLogonType LogonType, Object sddl)
at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String Path, TaskDefinition definition, TaskCreation createType, String UserId, String password, TaskLogonType LogonType, String sddl)
at Microsoft.Win32.TaskScheduler.TaskService.AddTask(String path, Trigger trigger, Action action, String UserId, String Password, TaskLogonType LogonType)
at WrapperDemo.Program.Main(String[] args) in C:\Users\lhuang2\Documents\Visual Studio 2015\Projects\WrapperDemo\WrapperDemo\Program.cs:line 20

Viewing all articles
Browse latest Browse all 2206

Trending Articles