Hi All,
Just to look at permission .
I ran the program as Administrator and the issue was gone. If I want it can be run in other user , it possible use a
UnauthorizedAccessException ?.
Let said it not secure in LocalSystem.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management;
using System.Diagnostics;
using System.Threading;
using System.IO;
namespace mag_3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ManagementEventWatcher stopWatch = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStopTrace"));
try
{
stopWatch.EventArrived += new EventArrivedEventHandler(this.Bulk_);
stopWatch.Start();
}
catch (Exception)
{
MessageBox.Show("Can't start the Process-Monitor! Are you running as admin?");
return;
}
}
private void Bulk_(object sender, EventArrivedEventArgs e)
{
Invoke(new MethodInvoker(() =>
{
listBox1.Items.Add(string.Format("Process stop: {0}", e.NewEvent.Properties["Second.exe"].Value));
}));
}
}
}