TaskLogonType.Group Error on Windows 7 professional

Topics: Errors
May 31 at 2:51 AM
I need to create a task that will from time to time on different user admin accounts .
So, when I try using the "Principal.LogonType = TaskLogonType.Group;" on my computer with Windows 8, it works fine, but when I use this on a Windows 7 professional, it gives an error on the "LogonType".

I just get a code from you to test this.
                TaskService ts = new TaskService();
                TaskDefinition td = ts.NewTask();
                td.RegistrationInfo.Description = "Run  teste ";
                td.Settings.DisallowStartIfOnBatteries = false;
                td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
                td.Principal.GroupId = "BUILTIN\\Administrators";
                td.Principal.LogonType = TaskLogonType.Group;
                td.Triggers.Add(new LogonTrigger());
                td.Actions.Add(new ExecAction(Application.StartupPath + "\\teste.exe", null, null));
                ts.RootFolder.RegisterTaskDefinition("teste", td);

                MessageBox.Show("Test Ok");
            catch (Exception ex)
                MessageBox.Show("ex: " + ex.ToString());
If I change the "TaskLogonType.Group;" to another type, it doesn't give any error, but it doesn't work, because I need to run as Administrators.

The error message is:
COMException (0x80070534):(49,8):LogonType : in RegisterTaskDefinition in C:\Users\dahall\Documentos\VisualStudio2010\Projects\TaskService\TaskFolder.cs:line448 and line 391
Jun 1 at 6:22 PM
Please try registering the task with the group information and let me know if that fixes the problem:
// Leave all setup code the same
ts.RootFolder.RegisterTaskDefintion("teste", td, TaskCreation.CreateOrUpdate, "BUILTIN\\Administrators", null, TaskLogonType.Group);
Jun 1 at 11:40 PM
I tried that as well. It gives the same error.
Jun 5 at 12:38 PM
So, do you have any other idea? Or perhaps another version for me to try?
Jun 9 at 11:15 PM
I have just tested this while running under an account with Admin rights under Windows 7 (Version 6.1 Build 7601: SP1). I ran your exact code while built against the .NET 2.0 and 4.0 versions of the library. I repeatedly did not see your error.

My guess is that it then has something to do with the user permissions under which you are running while executing on Windows 7. Make sure that account has Admin rights.
Jun 11 at 3:10 AM
Yes, all accounts have Admin rights