Quantcast
Viewing all articles
Browse latest Browse all 2206

New Post: task launches as scheduled, but doesn't graphically show Notepad

I have some code which I use to schedule a task to launch notepad.exe after 2 minutes have elapsed.

The process seems to start fine, but the program doesn't show up in the UI.

Please help.

Here is the code:
        Dim ts As New TaskService
        Dim td As TaskDefinition = ts.NewTask

        Dim tf As TaskFolder = ts.RootFolder

        td.RegistrationInfo.Description = "Test action"
        td.Principal.LogonType = TaskLogonType.S4U
        td.Settings.DisallowStartIfOnBatteries = False
        td.Settings.Hidden = False
        td.Settings.Priority = System.Diagnostics.ProcessPriorityClass.Normal
        td.Settings.RunOnlyIfIdle = False
        td.Settings.RunOnlyIfNetworkAvailable = False
        td.Settings.StopIfGoingOnBatteries = False

        td.Principal.RunLevel = TaskRunLevel.Highest
        td.Settings.AllowDemandStart = True
        td.Settings.AllowHardTerminate = True
        td.Settings.Compatibility = TaskCompatibility.V2
        td.Settings.DeleteExpiredTaskAfter = TimeSpan.FromMinutes(1)
        td.Settings.StartWhenAvailable = True

        Dim tt As New TimeTrigger

        td.Triggers.Add(tt)

        tt.StartBoundary = DateTime.Now + TimeSpan.FromMinutes(2)
        tt.EndBoundary = DateTime.Now + TimeSpan.FromMinutes(2)

        tt.Repetition.StopAtDurationEnd = True

        tt.Enabled = True

        td.Actions.Add(New ExecAction("notepad.exe", "C:\test.txt"))

        Try

        tf.RegisterTaskDefinition("TestNewest", td, TaskCreation.CreateOrUpdate, My.User.Name, , TaskLogonType.S4U)


        Catch ex As Exception
            Debug.Print(ex.ToString())
        End Try

        Debug.Print("Task registered, will run at " + CStr(DateTime.Now + TimeSpan.FromMinutes(2)))

Viewing all articles
Browse latest Browse all 2206

Trending Articles



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