Quantcast
Channel: Task Scheduler Managed Wrapper
Viewing all articles
Browse latest Browse all 2206

New Post: Task creation issue and login issue

$
0
0
When no user information is provided to the RegisterTaskDefinition method, it first looks to those provided to the Principal property and then uses the credentials of those provided to the TaskService constructor. It cannot give privileges higher than those provided to the TaskService instance. When no user information is provided to the TaskService constructor, it uses those of the executing assembly. Unless you have specifically setup a manifest file for your executable or run it using "Run as Administrator", then UAT will step in and reduce the account privileges dramatically.

I believe the following will correct your code:
' Create a new task definition and assign propertiesDim td As TaskDefinition = TaskService.Instance.NewTask
td.RegistrationInfo.Description = "Test Startup"'Create trigger that fires 1 minutes after the system starts.Dim lt As LogonTrigger = New LogonTrigger()
lt.Delay = TimeSpan.FromMinutes(1)
'Set trigger to only fire for this account so elevated permissions are not needed
lt.UserId = Environment.UserName
td.Triggers.Add(lt)
'The Add method assumes an ExecAction when the parameters are strings
td.Actions.Add("C:\test.exe")
td.Principal.RunLevel = TaskRunLevel.Highest
td.Settings.Compatibility = TaskCompatibility.V2_1
TaskService.Instance.RootFolder.RegisterTaskDefinition("test app", td)

Viewing all articles
Browse latest Browse all 2206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>