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

TaskEditDialog SecurityException thrown

Dec 6, 2011 at 5:18 PM

I current have the following code to access the TaskEditDialog

Microsoft.Win32.TaskScheduler.TaskEditDialog dlg = new Microsoft.Win32.TaskScheduler.TaskEditDialog(task, true, true);
dlg.ShowDialog();  

however if the user clicks on the "Conditions" tab it throws a System.Security.SecurityException with the following message  

System.Security.SecurityException: Requested registry access is not allowed.
   at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
   at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
   at Microsoft.Win32.RegistryKey.OpenSubKey(String name)
   at Microsoft.Win32.TaskScheduler.NetworkProfile.GetAllLocalProfiles()
   at Microsoft.Win32.TaskScheduler.TaskPropertiesControl.conditionsTab_Enter(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnEnter(EventArgs e) ...

 

The code works, without throwing an exception if I am running my program as Administrator, but as this is part of a larger project I am unable to enforce this issue.

I am currently using Windows 7. Is there any way to get round this problem?

Coordinator
Dec 6, 2011 at 7:19 PM

You have identified a bug which I have fixed in the code drop 72934 and will be released with the 1.7.1 download.

Dec 7, 2011 at 12:13 PM

Thanks for the speedy reply, but unfortunately it does not fix the issue I am experiencing. I have installed the source code, set a breakpoint and it is hitting an exception on NetworkProfiles line 93 in the public static NetworkProfile[] GetAllLocalProfiles() method.

 

I put a try-catch around this method, identical to your fix in the constructor and it seems to fix the issue, however I am unsure whether that would be the best solution for the problem.

 

Also, I have noticed on the conditions tab (if I have that try-catch in place) that if I select "start this task only if computer is idle for" checkbox, but do not change the value in the time combi list it won't save the option.

Coordinator
Dec 7, 2011 at 8:05 PM

Can you tell me what the behavior is on this system when clicking the "Conditions" tab using the system "Task Scheduler" application in "Start Menu | Accessories | System Tools"? That will help me know how I should update the library.

Coordinator
Dec 7, 2011 at 10:18 PM

I just made some big changes to the code and checked it in. Will you try the new code and tell me if you still experience problems?

Dec 8, 2011 at 8:53 AM

Thanks, the new code seems to fix the problem I was experiencing with the exceptions with the registry access.

 

I am still having problems with it not saving a changed state to the "start task only if computer idle for" checkbox unless the combo box has been changed on the conditions tab.

Coordinator
Dec 8, 2011 at 8:31 PM

The system library defaults the value of the IdleDuration to 10 minutes and the value of the WaitTimeout to 1 hour. If you leave those two values as the default, then the checkbox will not show they have been set. I have looked at ways to capture that it is set, but not defaulting, and have come up empty.

Dec 9, 2011 at 8:28 AM

Fair enough. Thanks for the help getting this sorted.