ManagementEventWatcher.Start() 拒绝访问
ManagementEventWatcher.Start() Access Denied
我正在尝试在 C#.Net 中创建一个应用程序,我需要它来扫描用户启动和停止的进程,但我在 .Start()
这是我目前得到的
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Management;
using Security;
using MySQLConnectivity;
namespace MyApp
{
public partial class Login : Form
{
MySQLClass sql = new MySQLClass();
ManagementEventWatcher processStartEvent = new ManagementEventWatcher("SELECT * FROM Win32_ProcessStartTrace");
ManagementEventWatcher processStopEvent = new ManagementEventWatcher("SELECT * FROM Win32_ProcessStopTrace");
public Login()
{
InitializeComponent();
processStartEvent.EventArrived += new EventArrivedEventHandler(processStartEvent_EventArrived);
processStartEvent.Start();
processStopEvent.EventArrived += new EventArrivedEventHandler(processStopEvent_EventArrived);
processStopEvent.Start();
}
void processStartEvent_EventArrived(object sender, EventArrivedEventArgs e)
{
string processName = e.NewEvent.Properties["ProcessName"].Value.ToString();
string processID = Convert.ToInt32(e.NewEvent.Properties["ProcessID"].Value).ToString();
MessageBox.Show("Process started. Name: " + processName + " | ID: " + processID);
}
void processStopEvent_EventArrived(object sender, EventArrivedEventArgs e)
{
string processName = e.NewEvent.Properties["ProcessName"].Value.ToString();
string processID = Convert.ToInt32(e.NewEvent.Properties["ProcessID"].Value).ToString();
MessageBox.Show("Process stopped. Name: " + processName + " | ID: " + processID);
}
}
}
我搜索了在线时间,但找不到任何内容。遇到这个问题的人是远程遇到的,而不是本地遇到的。我正在使用 Windows Pro 8.1 + Microsoft Visual Studio Ultimate 2013,以防万一 VS 或 OS 的版本在这种情况下可能很重要。
问题在 processStartEvent.Start()
说 "Access denied" 时触发。
我也尝试从 .Start()
切换到 .WaitForNextEvent()
,结果相同
我在这里遗漏了什么吗?
ClickOnce 已激活。禁用它解决了我的问题。谢谢。
我正在尝试在 C#.Net 中创建一个应用程序,我需要它来扫描用户启动和停止的进程,但我在 .Start()
这是我目前得到的
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Management;
using Security;
using MySQLConnectivity;
namespace MyApp
{
public partial class Login : Form
{
MySQLClass sql = new MySQLClass();
ManagementEventWatcher processStartEvent = new ManagementEventWatcher("SELECT * FROM Win32_ProcessStartTrace");
ManagementEventWatcher processStopEvent = new ManagementEventWatcher("SELECT * FROM Win32_ProcessStopTrace");
public Login()
{
InitializeComponent();
processStartEvent.EventArrived += new EventArrivedEventHandler(processStartEvent_EventArrived);
processStartEvent.Start();
processStopEvent.EventArrived += new EventArrivedEventHandler(processStopEvent_EventArrived);
processStopEvent.Start();
}
void processStartEvent_EventArrived(object sender, EventArrivedEventArgs e)
{
string processName = e.NewEvent.Properties["ProcessName"].Value.ToString();
string processID = Convert.ToInt32(e.NewEvent.Properties["ProcessID"].Value).ToString();
MessageBox.Show("Process started. Name: " + processName + " | ID: " + processID);
}
void processStopEvent_EventArrived(object sender, EventArrivedEventArgs e)
{
string processName = e.NewEvent.Properties["ProcessName"].Value.ToString();
string processID = Convert.ToInt32(e.NewEvent.Properties["ProcessID"].Value).ToString();
MessageBox.Show("Process stopped. Name: " + processName + " | ID: " + processID);
}
}
}
我搜索了在线时间,但找不到任何内容。遇到这个问题的人是远程遇到的,而不是本地遇到的。我正在使用 Windows Pro 8.1 + Microsoft Visual Studio Ultimate 2013,以防万一 VS 或 OS 的版本在这种情况下可能很重要。
问题在 processStartEvent.Start()
说 "Access denied" 时触发。
我也尝试从 .Start()
切换到 .WaitForNextEvent()
,结果相同
我在这里遗漏了什么吗?
ClickOnce 已激活。禁用它解决了我的问题。谢谢。