taskservice

c# : Create windows scheduled task as a different user

左心房为你撑大大i 提交于 2019-12-11 02:01:36
问题 I'm creating Windows Scheduled Tasks dynamically from c# using the build-in TaskService and TaskDefinition libraries. But for some of them, we need to create then to run as a different user (Local Service or Network Service). As the tasks are created and removed dynamically we cannot edit all of them manually to change the user. We need to do it via code. Is is possible? I've tried the following settings: TaskDefinition.Principal.Id = "NETWORK SERVICE"; TaskDefinition.Principal.LogonType =