public void Refresh() { if (_v2RunningTask != null) { _v2RunningTask.Refresh(); } }
static public bool SkipUacRun(string taskName, string[] args = null) { bool silent = true; try { TaskScheduler.TaskScheduler service = new TaskScheduler.TaskScheduler(); service.Connect(); ITaskFolder folder = service.GetFolder(@"\"); // root IRegisteredTask task = folder.GetTask(taskName); silent = false; AppLog.Line("Trying to SkipUAC ..."); IExecAction action = (IExecAction)task.Definition.Actions[1]; if (action.Path.Equals(System.Reflection.Assembly.GetExecutingAssembly().Location, StringComparison.CurrentCultureIgnoreCase)) { string arguments = args == null ? "" : ("\"" + string.Join("\" \"", args) + "\""); IRunningTask running_Task = task.RunEx(arguments, (int)_TASK_RUN_FLAGS.TASK_RUN_NO_FLAGS, 0, null); for (int i = 0; i < 5; i++) { Thread.Sleep(250); running_Task.Refresh(); _TASK_STATE state = running_Task.State; if (state == _TASK_STATE.TASK_STATE_RUNNING || state == _TASK_STATE.TASK_STATE_READY || state == _TASK_STATE.TASK_STATE_DISABLED) { if (state == _TASK_STATE.TASK_STATE_RUNNING || state == _TASK_STATE.TASK_STATE_READY) { return(true); } break; } } } } catch (Exception err) { if (!silent) { AppLog.Line("SkipUAC Error {0}", err.ToString()); } } return(false); }