Hi All,
I use the ManagementEventWatcher to detect program "Third" .If program "Third" begin running then the program "Second" automatically start to monitoring my computer.somebody can show the true coding.
Here is code ;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _Exe_5F
{
public partial class Form1 : Form
{
string query = "SELECT * FROM __InstanceCreationEvent " + "WITHIN 1 WHERE " + "TargetInstance isa \"Win32_Process\"";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ManagementEventWatcher watcher = new ManagementEventWatcher(query);
watcher.EventArrived += new EventArrivedEventHandler(Start_Bulk);
watcher.Start();
}
private void Start_Bulk(object sender, EventArrivedEventArgs e)
{
ManagementBaseObject targetInstance = (ManagementBaseObject)e.NewEvent["TargetInstance"];
Invoke(new Action(() => listBox1.Items.Add(targetInstance["Name"])));
foreach (var property in targetInstance.Properties)
{
try
{
string name = property.Value.ToString();
if (name == "Third")
{
try
{
using (Process myProcess = new Process())
{
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = "C:\\Users\\family\\Desktop\\Second.exe.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
}
}
catch (Exception)
{
}
}
}
catch
{
}
}
}
}
}