我正在使用来自 Codeplex 的 Task Scheduler Managed Wrapper。我面临一个奇怪的问题。我正在尝试枚举多个远程服务器(V1 和 V2)中的任务,然后在数据网格中显示这些任务。当我连接到 V1 服务器(使用 forceV1=true)时,会发生此问题。枚举工作正常 - 数据甚至被传递到网格。但是,当我将光标移到网格上时,我得到一个 SecurityException 说“不允许请求的注册表访问”。有谁知道发生了什么?
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; }
}