using Microsoft.Win32.TaskScheduler;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RDP
{
    public partial class Form1 : Form
    {
        private EventLog eventLog;
        public Form1()
        {
            InitializeComponent();
        }

        private void btnTaskScheduler_Click(object sender, EventArgs e)
        {
            eventLog = new EventLog("Security");
            eventLog.EntryWritten += new EntryWrittenEventHandler(OnEntryWritten);
            eventLog.EnableRaisingEvents = true;

            MessageBox.Show("EventLog created successfully.");
        }
        private void OnEntryWritten(object source, EntryWrittenEventArgs e)
        {
            if (e.Entry.EventID == 4625)
            {
                using (TaskService ts = new TaskService())
                {
                    TaskDefinition td = ts.NewTask();
                    td.RegistrationInfo.Description = "Task created by my app";
                    td.Triggers.Add(new EventTrigger("Security", "4625", 1));
                    td.Actions.Add(new ExecAction(Application.ExecutablePath));
                    ts.RootFolder.RegisterTaskDefinition("MyTask", td);
                }

                MessageBox.Show("Task Scheduler task created successfully.");
            }
        }

    }
}
Editör

Kod Bilgileri

Kodun Sahibi: A
Tarih: 14/03/2023 16:22:46