I'm using Task Scheduler Managed Wrapper from Codeplex. I am facing a weird issue. I am trying to enumerate tasks in multiple remote servers (V1 and V2) and then display the tasks in a datagrid. This issue happens when I am connecting to a V1 server (using forceV1=true). The enumeration works fine - the data is passed to the grid even. But as soon as I move my cursor over the grid, I get a SecurityException saying 'Requested registry access is not allowed.' Does anyone know what's going on?
public partial class MainWindow : Window
{
public MainWindow()
{
String osVer;
using (var reg = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "deves07"))
using (var key = reg.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\"))
{
osVer = string.Format("Name:{0}, Version:{1}", key.GetValue("ProductName"), key.GetValue("CurrentVersion"));
}
TaskService ts;
if (osVer.Contains("2003"))
{
ts = new TaskService("REMOTE", "username", "domain", "password", true);
}
else
{
ts = new TaskService("REMOTE", "username", "domain", "password");
}
List<TaskInfo> taskList = new List<TaskInfo>();
EnumFolderTasks(ts.RootFolder, taskList);
DataContext = taskList;
}
void EnumFolderTasks(TaskFolder fld, List<TaskInfo> taskLst)
{
Debug.WriteLine(fld.Name);
foreach (Task task in fld.Tasks)
taskLst.Add(ActOnTask(task));
foreach (TaskFolder sfld in fld.SubFolders)
EnumFolderTasks(sfld, taskLst);
}
TaskInfo ActOnTask(Task t)
{
TaskInfo taskInfo = new TaskInfo();
taskInfo.Name = t.Name;
taskInfo.isRunning = t.IsActive;
taskInfo.NextRunTime = t.NextRunTime;
taskInfo.LastRunTime = t.LastRunTime;
//taskInfo.LastRunStatus = t.LastTaskResult;
return taskInfo;
}
}
public class TaskInfo
{
public string Name { set; get; }
public bool isRunning { set; get; }
public DateTime NextRunTime { set; get; }
public DateTime LastRunTime { set; get; }
public int LastRunStatus { set; get; }
}
This is courtesy of dahall over at codeplex (Thanks a lot dahall)
First, try putting brackets in around the scope of your first
using
statement. You can also do the same with theTaskService
instance. You could do this by doing:List<TaskInfo> taskList = new List<TaskInfo>(); using (TaskService ts = new TaskService(REMOTE", "username", "domain", "password", osVer.Contains("2003"))) { EnumFolderTasks(ts.RootFolder, taskList); } DataContext = taskList;
I am not sure why this happens only for the V1 calls, but this did solve my problem.