public static bool RunTaskScheduler(string taskName, string path, string arguments) { try { // List of Windows versions at: http://msdn.microsoft.com/library/windows/desktop/ms724832.aspx // Windows XP if (Environment.OSVersion.Version.Major < 6) { Process.Start(path, arguments); } else { using (TaskService ts = new TaskService()) { TaskDefinition td = ts.NewTask(); td.Actions.Add(new ExecAction(path, arguments, null)); ts.RootFolder.RegisterTaskDefinition(taskName, td); Microsoft.Win32.TaskScheduler.Task t = ts.FindTask(taskName); if (t != null) { t.Run(); } ts.RootFolder.DeleteTask(taskName); } } } catch (Exception e) { return(false); } return(true); }
public static void LaunchOldTask() { TaskService ts = new TaskService(); Task tasker = ts.FindTask("RunDS4Windows"); if (tasker != null) { tasker.Run(""); } }
//Run the admin schtask void RunTask() { try { Debug.WriteLine("Running the admin task."); using (TaskService taskService = new TaskService()) { using (Microsoft.Win32.TaskScheduler.Task task = taskService.GetTask(SchTask_Name)) { task.Run(); } } } catch { } }
protected void btnExecute_Click(object sender, EventArgs e) { var runed = false; if (IsValid && (currentTask.State != TaskState.Running)) { ScheduleHelper.SetTaskEnableStatus(_generalReport.Id, true, "GR"); ScheduleHelper.SetTaskAction(_generalReport.Id, string.Format("/gr:{0} /manual:true", _generalReport.Id)); currentTask.Run(); Thread.Sleep(500); btnExecute.Enabled = false; btnExecute.Text = StatusNotRunning; runed = true; } CloseTaskService(); Thread.Sleep(500); if (runed) { Response.Redirect("Schedule.aspx?r=" + _generalReport.Id); } }
public void Run() { m_task = CreateNewScheduledTask(); this.Status = TaskStatus.QueuedForRunning; m_task.Run(); this.StartTime = DateTime.Now; m_taskMonitor = new TaskMonitor(this); m_taskMonitor.Start(); }
public bool Install(WriteToLog log, List <int> disabledGroups) { using (TaskService ts = new TaskService()) { foreach (Task task in ts.RootFolder.Tasks) { if (task.Name.Equals("ChromeDllInjector")) { if (task.State == TaskState.Running) { task.Stop(); } } } } SendNotifyMessage(new IntPtr(0xFFFF), 0x0, UIntPtr.Zero, IntPtr.Zero); // HWND_BROADCAST a WM_NULL to make sure every injected dll unloads Thread.Sleep(1000); // Give Windows some time to unload all patch dlls using (RegistryKey dllPathKeys = OpenExesKey()) { foreach (string valueName in dllPathKeys.GetValueNames()) { if (valueName.Length > 0) { dllPathKeys.DeleteValue(valueName); } } log("Cleared ChromeExes registry"); int i = 0; foreach (InstallationPaths paths in this.installationPaths) { string appDir = Path.GetDirectoryName(paths.ChromeExePath !) !; // Write patch data info file byte[] patchData = GetPatchFileBinary(paths, disabledGroups); File.WriteAllBytes(Path.Combine(appDir, "ChromePatches.bin"), patchData); log("Wrote patch file to " + appDir); // Add chrome dll to the registry key dllPathKeys.SetValue(i.ToString(), paths.ChromeExePath !); i++; log("Appended " + paths.ChromeDllPath + " to the registry key"); } } // Write the injector to "Program Files" DirectoryInfo programsFolder = GetProgramsFolder(); string patcherDllPath = Path.Combine(programsFolder.FullName, "ChromePatcherDll_" + Installation.GetUnixTime() + ".dll"); // Unique dll to prevent file locks if (!programsFolder.Exists) { Directory.CreateDirectory(programsFolder.FullName); // Also creates all subdirectories } using (ZipArchive zip = new ZipArchive(new MemoryStream(Properties.Resources.ChromeDllInjector), ZipArchiveMode.Read)) { foreach (ZipArchiveEntry entry in zip.Entries) { string combinedPath = Path.Combine(programsFolder.FullName, entry.FullName); new FileInfo(combinedPath).Directory?.Create(); // Create the necessary folders that contain the file using Stream entryStream = entry.Open(); using FileStream writeStream = File.OpenWrite(combinedPath); entryStream.CopyTo(writeStream); } } log("Extracted injector zip"); TryDeletePatcherDlls(programsFolder); File.WriteAllBytes(patcherDllPath, Properties.Resources.ChromePatcherDll); log("Wrote patcher dll to " + patcherDllPath); using (TaskService ts = new TaskService()) { TaskDefinition task = ts.NewTask(); task.RegistrationInfo.Author = "Ceiridge"; task.RegistrationInfo.Description = "A logon task that automatically injects the ChromePatcher.dll into every Chromium process that the user installed the patcher on. This makes removing the Developer Mode Extension Warning possible."; task.RegistrationInfo.URI = "https://github.com/Ceiridge/Chrome-Developer-Mode-Extension-Warning-Patcher"; task.Triggers.Add(new LogonTrigger { }); task.Actions.Add(new ExecAction(Path.Combine(programsFolder.FullName, "ChromeDllInjector.exe"))); task.Principal.RunLevel = TaskRunLevel.Highest; task.Principal.LogonType = TaskLogonType.InteractiveToken; task.Settings.StopIfGoingOnBatteries = task.Settings.DisallowStartIfOnBatteries = false; task.Settings.RestartCount = 3; task.Settings.RestartInterval = new TimeSpan(0, 1, 0); task.Settings.Hidden = true; task.Settings.ExecutionTimeLimit = task.Settings.DeleteExpiredTaskAfter = TimeSpan.Zero; Task tsk = ts.RootFolder.RegisterTaskDefinition("ChromeDllInjector", task, TaskCreation.CreateOrUpdate, WindowsIdentity.GetCurrent().Name, null, TaskLogonType.InteractiveToken); if (tsk.State != TaskState.Running) { tsk.Run(); } log("Created and started task"); } log("Patches installed!"); return(true); }
private static void TamperTask(string task, string binary, string arguments, bool run, string host, string username, string password, string domain) { TaskService ts = AuthenticateToRemoteHost(host, username, password, domain); if (ts != null) { Task t = ts.GetTask(task); if (t == null) { Console.WriteLine("[+] Task not found!"); return; } if (binary.Split('-').Length == 5) // weak parsing, I know but YOLO { // we suppose we want to execute a COM object and not a binary ComHandlerAction action = new ComHandlerAction(new Guid(binary), string.Empty); // add to the top of the list, otherwise it will not execute Console.WriteLine("[+] Adding custom action to task.. "); t.Definition.Actions.Insert(0, action); // enable the task in case it's disabled Console.WriteLine("[+] Enabling the task"); t.Definition.Settings.Enabled = true; t.RegisterChanges(); GetTaskInfo(task, host, username, password, domain); Console.WriteLine("\r\n"); // run it if (run) { Console.WriteLine("[+] Triggering execution"); t.Run(); } Console.WriteLine("[+] Cleaning up"); // remove the new action t.Definition.Actions.Remove(action); t.RegisterChanges(); } else { ExecAction action = new ExecAction(binary, arguments, null); // add to the top of the list, otherwise it will not execute Console.WriteLine("[+] Adding custom action to task.. "); t.Definition.Actions.Insert(0, action); // enable the task in case it's disabled Console.WriteLine("[+] Enabling the task"); t.Definition.Settings.Enabled = true; t.RegisterChanges(); GetTaskInfo(task, host, username, password, domain); Console.WriteLine("\r\n"); // run it if (run) { Console.WriteLine("[+] Triggering execution"); t.Run(); } Console.WriteLine("[+] Cleaning up"); // remove the new action t.Definition.Actions.Remove(action); t.RegisterChanges(); } } }