[英]ManagementEventWatcher.Start() Access Denied
I'm trying to create an application in C#.Net, and I need it to scan the processes that the user start and stop, but I'm getting an "Access Denied" on the .Start()
我正在尝试在 C#.Net 中创建一个应用程序,我需要它来扫描用户启动和停止的进程,但是我在
.Start()
上收到“拒绝访问”
Here is what I've got so far这是我到目前为止所得到的
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);
}
}
}
I've searched online hours, but couldn't find anything.我已经搜索了在线时间,但找不到任何内容。 People that had this problem, had it remotelly, and not locally.
遇到这个问题的人是远程解决的,而不是本地解决的。 I am using Windows Pro 8.1 + Microsoft Visual Studio Ultimate 2013, just in case that versions of VS or OS may be important in this case.
我使用的是 Windows Pro 8.1 + Microsoft Visual Studio Ultimate 2013,以防万一在这种情况下 VS 或 OS 的版本可能很重要。
The problem triggers on processStartEvent.Start()
saying "Access denied".问题在
processStartEvent.Start()
上触发,提示“拒绝访问”。 I also tried to switch from .Start()
to .WaitForNextEvent()
with the same result我还试图从开关
.Start()
到.WaitForNextEvent()
具有相同的结果
Anything that I'm missing here?我在这里缺少什么吗?
ClickOnce was activated. ClickOnce 已激活。 Disabling it solved my problem.
禁用它解决了我的问题。 Thanks tho.
谢谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.