簡體   English   中英

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()上觸發,提示“拒絕訪問”。 我還試圖從開關.Start().WaitForNextEvent()具有相同的結果

我在這里缺少什么嗎?

ClickOnce 已激活。 禁用它解決了我的問題。 謝謝你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM