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

System.IO.FileNotFoundException when selecting run times From/To dates on Vista and Win 7

Jun 11, 2012 at 2:40 PM
Edited Jun 11, 2012 at 2:58 PM

Environment:
Windows Vista Business SP2 32 or 64-bit
Windows 7 Pro SP1 64-bit
 
The Problem:
Any attempt to select the dates in the "From" or "To" Calendar drop downs of the "Run Times" tab of the Task Scheduler editor on 32 or 64-bit Vista or
Windows 7 is returning a System.IO.FileNotFoundException. The problem does not reproduce on XP Pro SP3 or 64-bit XP Pro SP2.

Exception details:
The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
 
Exception type: System.IO.FileNotFoundException
Message:         The system cannot find the file specified. (Exception from
HRESULT: 0x80070002)
Source:         Microsoft.Win32.TaskScheduler
Target Site:     GetRunTimes
 
System.IO.FileNotFoundException was unhandled by user code
  Message=The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
  Source=Microsoft.Win32.TaskScheduler
  StackTrace:
       at Microsoft.Win32.TaskScheduler.V2Interop.IRegisteredTask.GetRunTimes(SystemTime& pstStart, SystemTime& pstEnd, UInt32& pCount, IntPtr& pRunTimes)
       at Microsoft.Win32.TaskScheduler.Task.GetRunTimes(DateTime start, DateTime end, UInt32 count) in C:\develop\git_repos\Framework\Utilities\Source\TaskService\Task.cs:line 791
       at Microsoft.Win32.TaskScheduler.TaskRunTimesControl.Fetch() in C:\develop\git_repos\Framework\Utilities\Source\TaskEditor\TaskRunTimesControl.cs:line 110
       at Microsoft.Win32.TaskScheduler.TaskRunTimesControl.dateValueChanged(Object sender, EventArgs e) in C:\develop\git_repos\Framework\Utilities\Source\TaskEditor\TaskRunTimesControl.cs:line 105
       at Microsoft.Win32.TaskScheduler.FullDateTimePicker.OnValueChanged(EventArgs eventArgs) in C:\develop\git_repos\Framework\Utilities\Source\TaskEditor\FullDateTimePicker.cs:line 239
       at Microsoft.Win32.TaskScheduler.FullDateTimePicker.subControl_ValueChanged(Object sender, EventArgs e) in C:\develop\git_repos\Framework\Utilities\Source\TaskEditor\FullDateTimePicker.cs:line 320
       at System.Windows.Forms.DateTimePicker.OnValueChanged(EventArgs eventargs)
       at System.Windows.Forms.DateTimePicker.WmDateTimeChange(Message& m)
       at System.Windows.Forms.DateTimePicker.WmReflectCommand(Message& m)
       at System.Windows.Forms.DateTimePicker.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  InnerException:

Coordinator
Jun 13, 2012 at 6:05 PM

Fixed in changeset 78634. Thanks for reporting this.

Jun 13, 2012 at 6:50 PM

Awesome! Thanks David!

Dec 5, 2013 at 6:49 AM
I don't think it is fixed - I ran into same problem on 64 bit Windows 7 (but just tested on another 64bit Windows 8 machine, works fine) - version i used is

Microsoft.Win32.TaskScheduler.dll (dll timestamp - 17 Sept 2013)
Coordinator
Jan 7, 2014 at 9:30 PM
Edited Jan 7, 2014 at 10:15 PM
I believe this is fixed, again, with version 2.0.3.
Jun 30, 2015 at 1:17 PM
At the moment I'm running into this problem on 64 bit Windows 10 Pro Insider Preview Build 10158. Same call works on 64 bit Windows 8.1 Pro.

System.IO.FileNotFoundException, The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
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)

Used .NET-Framework 2.0 - Version 2.3.4.0
Coordinator
Jun 30, 2015 at 6:06 PM
Crayjin: what are you putting in for the "createType" parameter? Make sure it is CreateOrUpdate or Create. If that is still not working, try running the process in an elevated account with "Run as Administrator". Sometimes there are permission problems that seem more prevalent the new the OS version.
Jul 7, 2015 at 8:41 AM
Hi dahall,

thanks for your response.

In fact I'm using the TaskCreation.CreateOrUpdate enum value and the process is elevated. Let me give you some more information:

I'm using a RegistrationTrigger, with a delay of 8 seconds and a EndBoundary of 20 seconds.
  • RunLevel is TaskRunLevel.LUA
  • DeleteExpiredTaskAfter is 40 seconds
  • Principal.UserId is the UserName of the Win32_ComputerSystem ManagementObject (Example: WIN-GVLEGB4ESV6\Test )
If you need further information, I'm also available on other communication channels.
Coordinator
Jul 7, 2015 at 5:26 PM
Will you post the code you are using to build the task and register it? I have a Win10 instance I can test it against. I'm not getting the failure building it out on my own.
Jul 9, 2015 at 2:26 PM
Hi dahall,

here my code:
using System;
using Microsoft.Win32.TaskScheduler;
using System.Management;

namespace TestTaskScheduler
{
    class Program
    {
        static void Main(string[] args)
        {

            var ts = new TaskService();

            TaskDefinition td = ts.NewTask();
            td.RegistrationInfo.Description = "some description";
            td.Principal.LogonType = TaskLogonType.InteractiveToken;

            var computerSystemClass = new ManagementClass("Win32_ComputerSystem");
            var computerSystems = computerSystemClass.GetInstances();
            var enumerator = computerSystems.GetEnumerator();
            while (enumerator.MoveNext())
            {
                var computerSystem = enumerator.Current;
                td.Principal.UserId = (string)computerSystem["UserName"];
            }

            td.Actions.Add(new ExecAction("cmd.exe", "-someparameter"));

            // Create Trigger
            var trigger = new RegistrationTrigger { Enabled = true };
            trigger.Delay = TimeSpan.FromSeconds(8);
            trigger.EndBoundary = DateTime.Now + TimeSpan.FromSeconds(20);
            td.Triggers.Add(trigger);

            TaskFolder tf = ts.RootFolder;

            td.Principal.RunLevel = TaskRunLevel.LUA;

            td.Settings.StartWhenAvailable = true;
            td.Settings.Hidden = false;
            td.Settings.MultipleInstances = TaskInstancesPolicy.StopExisting;
            td.Settings.DisallowStartIfOnBatteries = false;
            td.Settings.StopIfGoingOnBatteries = false;
            td.Settings.IdleSettings.StopOnIdleEnd = false;
            td.Settings.DeleteExpiredTaskAfter = TimeSpan.FromSeconds(40);

            TaskFolder testFolder = null;

            foreach (TaskFolder taskFolder in tf.SubFolders)
            {
                if (taskFolder.Name.Equals("TEST", StringComparison.OrdinalIgnoreCase))
                {
                    testFolder = taskFolder;
                }
            }

            if (testFolder == null)
                testFolder = tf.CreateFolder("TEST");

            testFolder.RegisterTaskDefinition("Start", td, TaskCreation.CreateOrUpdate, null, null, TaskLogonType.InteractiveToken);
            Console.ReadKey();
        }
    }
}


Coordinator
Jul 10, 2015 at 2:08 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Jul 10, 2015 at 2:09 AM
I've moved this to an issue.