Hi i got a really good solution.
What i did:
1. Open Task Scheduler - create manually 1 task
2. Configurate what i need in the task
3. Export to .xml file
4. Read each line and code it inside code
My code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TxtUseAccount.Text = Environment.UserDomainName & "\" & Environment.UserName
TxtAuthor.Text = Environment.UserDomainName & "\" & Environment.UserName
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using ts As New TaskService
Dim td As TaskDefinition = ts.NewTask()
td.RegistrationInfo.Date = Date.Now() 'Date
td.RegistrationInfo.Author = TxtAuthor.Text 'User Account
td.RegistrationInfo.Description = TxtDescription.Text 'Description
td.RegistrationInfo.URI = TxtLocation.Text + TxtName.Text
'Add a general logon trigger
td.Triggers.Add(New LogonTrigger With {
.UserId = Security.Principal.WindowsIdentity.GetCurrent().Name, .Enabled = True
})
'Principals
td.Principal.Id = TxtAuthor.Text 'User Account
td.Principal.LogonType = TaskLogonType.InteractiveToken
td.Principal.RunLevel = TaskRunLevel.Highest 'High Privilegies
'Settings
td.Settings.MultipleInstances = TaskInstancesPolicy.IgnoreNew 'Policy Setting
td.Settings.DisallowStartIfOnBatteries = False 'Disable Battery
td.Settings.StopIfGoingOnBatteries = False 'Stop if on battery
td.Settings.AllowHardTerminate = False 'Disable Terminate
td.Settings.StartWhenAvailable = False 'Start Task when avaliable
td.Settings.RunOnlyIfNetworkAvailable = False 'Run Task if avaliable network
td.Settings.IdleSettings.StopOnIdleEnd = False 'Stop Task if idle ends
td.Settings.IdleSettings.RestartOnIdle = False 'Restart Task on idle
td.Settings.AllowDemandStart = True 'Allow Demand Start
td.Settings.Enabled = True 'Is Task Enabled
td.Settings.Hidden = False 'Is it Hidden?
td.Settings.RunOnlyIfIdle = False 'Run only if Idle
td.Settings.WakeToRun = False 'On wake up Run
td.Settings.ExecutionTimeLimit = TimeSpan.Zero '0-Disable
td.Settings.Priority = ThreadPriorityLevel.Highest 'Priority Level
td.Settings.RestartCount = 3
td.Settings.RestartInterval = TimeSpan.FromMinutes(1)
' Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(New ExecAction(TxtPathExe.Text, Nothing, Nothing))
ts.RootFolder.RegisterTaskDefinition(TxtLocation.Text + TxtName.Text, td)
End Sub
Boom perfect :)