This project has moved. For the latest updates, please go here.

COMException (0x80070534): (45,4):LogonType

May 6, 2011 at 7:15 AM

I've written a Windows service that uses the TaskScheduler library, and which, during startup, checks to see if certain tasks exist on the server, and if they don't, attempts to create them. Running on my developer PC, my code works just fine. However, when I switched to a VM running a clean installation of W2K8 R2, I get the following exception:

Service cannot be started. System.Runtime.InteropServices.COMException (0x80070534): (45,4):LogonType:
   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.TaskFolder.RegisterTaskDefinition(String Path, TaskDefinition definition)

at the point in my code when I try to create the task. The service is running under the WORKGROUP\SYSTEM account. Apart from granting that user account local Administrator privileges, is there anything else I can set to get this working?

May 6, 2011 at 4:56 PM

This is an expected error given the parameters you have specified (see Make sure when you call the RegisterTaskDefinition method, it looks something like this:

tf.RegisterTaskDefinition("Test", td, TaskCreation.CreateOrUpdate, "SYSTEM", null, TaskLogonType.ServiceAccount, null);

The other possibility is that this is a permissions problem. Make sure you have SeBatchLogonRight for the account trying to register the task.

May 8, 2011 at 11:43 PM

Just the code change was sufficient to fix the issue for me - many thanks for the quick and accurate response!