Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need more knowledge in c I don't know what you mean by this. is there something within this that iv posted wrong this is a

"Need more knowledge in c" I don't know what you mean by this. is there something within this that iv posted wrong

this is a c# forms program that picks up when a program starts and when it closes. Right now I have it set to where it picks up all processes and when they close but I'm trying to figure out how to make it where it picks up specific things and when they close like notepad or google chrome.

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.Diagnostics; using System.Management; using System.Runtime.InteropServices; using Microsoft.Win32;

namespace WindowsFormsApp8 { public partial class Form1 : Form { struct APPINFO {

}

private readonly List currentlyRunningProcesses = new List();

public Form1() { InitializeComponent(); ManagementEventWatcher AppStartQuery = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace")); ManagementEventWatcher AppStopQuery = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStopTrace"));

AppStartQuery.EventArrived += new EventArrivedEventHandler (StartedProcess); AppStartQuery.Start();

AppStopQuery.EventArrived += new EventArrivedEventHandler(StoppedProcess); AppStopQuery.Start();

Console.WriteLine("Exit"); Console.ReadLine();

} private void StartedProcess(object sender, EventArrivedEventArgs e) { try { //var processStart = Process.GetProcessById(Convert.ToInt32(e.NewEvent.Properties["processID"].Value.ToString())); //int processID = Process.GetProcessById(processStart.Id).Id; //string processName = Process.GetProcessById(processStart.Id).ProcessName; int processID = Convert.ToInt32(e.NewEvent.Properties["ProcessID"].Value.ToString()); string processName = e.NewEvent.Properties["ProcessName"].Value.ToString(); string name = "Process Name: ";

//richtextbox ProcessStart.Invoke(new Action(() => { ProcessStart.Text = ProcessStart.Text + DateTime.Now.ToString("MM/dd/yyyy hh:mm tt | ") + name.ToString() +processName.ToString() + processID.ToString(@" ID:0") + Environment.NewLine; })); } catch (Exception ee) { Console.WriteLine("Start Process Exception: "+ee.Message); } }

private void StoppedProcess(object sender, EventArrivedEventArgs e) { try {

//var processStop = Process.GetProcessById(Convert.ToInt32(e.NewEvent.Properties["processID"].Value.ToString()));

//int processID = Process.GetProcessById(processStop.Id).Id; //string processNamee = Process.GetProcessById(processStop.Id).ProcessName; int processID = Convert.ToInt32(e.NewEvent.Properties["ProcessID"].Value.ToString()); string processName = e.NewEvent.Properties["ProcessName"].Value.ToString(); string namee = "Process Name: ";

ProcessStop.Invoke(new Action(() => { ProcessStop.Text = ProcessStop.Text + DateTime.Now.ToString("MM/dd/yyyy hh:mm tt | ") + namee.ToString() + processName.ToString() + processID.ToString(@" ID:0") + Environment.NewLine; })); } catch (Exception ee) { Console.WriteLine("Stop Process Exception: " + ee.Message); } } private void Form1_Load(object sender, EventArgs e) {

} } }

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.Diagnostics; using System.Management; using System.Runtime.InteropServices; using Microsoft.Win32;

namespace WindowsFormsApp8 { public partial class Form1 : Form { struct APPINFO {

}

private readonly List currentlyRunningProcesses = new List();

public Form1() { InitializeComponent(); ManagementEventWatcher AppStartQuery = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace")); ManagementEventWatcher AppStopQuery = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStopTrace"));

AppStartQuery.EventArrived += new EventArrivedEventHandler (StartedProcess); AppStartQuery.Start();

AppStopQuery.EventArrived += new EventArrivedEventHandler(StoppedProcess); AppStopQuery.Start();

Console.WriteLine("Exit"); Console.ReadLine();

} private void StartedProcess(object sender, EventArrivedEventArgs e) { try { //var processStart = Process.GetProcessById(Convert.ToInt32(e.NewEvent.Properties["processID"].Value.ToString())); //int processID = Process.GetProcessById(processStart.Id).Id; //string processName = Process.GetProcessById(processStart.Id).ProcessName; int processID = Convert.ToInt32(e.NewEvent.Properties["ProcessID"].Value.ToString()); string processName = e.NewEvent.Properties["ProcessName"].Value.ToString(); string name = "Process Name: ";

//richtextbox ProcessStart.Invoke(new Action(() => { ProcessStart.Text = ProcessStart.Text + DateTime.Now.ToString("MM/dd/yyyy hh:mm tt | ") + name.ToString() +processName.ToString() + processID.ToString(@" ID:0") + Environment.NewLine; })); } catch (Exception ee) { Console.WriteLine("Start Process Exception: "+ee.Message); } }

private void StoppedProcess(object sender, EventArrivedEventArgs e) { try {

//var processStop = Process.GetProcessById(Convert.ToInt32(e.NewEvent.Properties["processID"].Value.ToString()));

//int processID = Process.GetProcessById(processStop.Id).Id; //string processNamee = Process.GetProcessById(processStop.Id).ProcessName; int processID = Convert.ToInt32(e.NewEvent.Properties["ProcessID"].Value.ToString()); string processName = e.NewEvent.Properties["ProcessName"].Value.ToString(); string namee = "Process Name: ";

ProcessStop.Invoke(new Action(() => { ProcessStop.Text = ProcessStop.Text + DateTime.Now.ToString("MM/dd/yyyy hh:mm tt | ") + namee.ToString() + processName.ToString() + processID.ToString(@" ID:0") + Environment.NewLine; })); } catch (Exception ee) { Console.WriteLine("Stop Process Exception: " + ee.Message); } } private void Form1_Load(object sender, EventArgs e) {

} } }

image text in transcribed

b Form1 x 03/16/2021 05:20 PM | Process Name: cmd.exe ID:6672 03/16/2021 05:20 PM I Process Name: conhost.exe ID:18960 03/16/2021 05:20 PM | Process Name: cmd.exe ID:9436 03/16/2021 05:20 PM | Process Name: conhost.exe ID:8900 03/16/2021 05:20 PMI Process Name: cmd.exe ID:23576 03/16/2021 05:20 PM | Process Name: conhost.exe ID:16672 03/16/2021 05:20 PM | Process Name: cmd.exe ID:16044 03/16/2021 05:20 PM | Process Name: conhost.exe ID:20584 03/16/2021 05:20 PMI Process Name: cmd.exe ID:13664 03/16/2021 05:20 PM I Process Name: conhost.exe ID:156 03/16/2021 05:20 PM Process Name: cmd.exe ID:25108 03/16/2021 05:20 PM | Process Name: conhost.exe ID:8120 03/16/2021 05:20 PM I Process Name: SnippingTool.exe ID:12624 03/16/2021 05:20 PM | Process Name: chrome.exe ID:9704 03/16/2021 05:20 PMI Process Name: chrome.exe ID:24672 03/16/2021 05:20 PMI Process Name: chrome.exe ID:14228 03/16/2021 05:20 PM | Process Name: chrome.exe ID:8376 03/16/2021 05:20 PM 1 Process Name: chrome.exe ID:9016 03/16/2021 05:20 PM | Process Name: chrome.exe ID:24092 03/16/2021 05:20 PMI Process Name: chrome.exe ID:17180 03/16/2021 05:20 PMI Process Name: chrome.exe ID:10672 03/16/2021 05:20 PM | Process Name: chrome.exe ID:1068 03/16/2021 05:20 PMI Process Name: chrome.exe ID:24788 03/16/2021 05:21 PMI Process Name: SnippingTool.exe ID:1508 03/16/2021 05:20 PMI Process Name: conhost.exe ID:20592 03/16/2021 05:20 PM | Process Name: cmd.exe ID:6672 03/16/2021 05:20 PM | Process Name: conhost.exe ID:18960 03/16/2021 05:20 PM | Process Name: cmd.exe ID:9436 03/16/2021 05:20 PM | Process Name: conhost.exe ID:8900 03/16/2021 05:20 PM | Process Name: cmd.exe ID:23576 03/16/2021 05:20 PM | Process Name: conhost.exe ID: 16672 03/16/2021 05:20 PM | Process Name: cmd.exe ID:16044 03/16/2021 05:20 PM 1 Process Name: conhost.exe ID:20584 03/16/2021 05:20 PM I Process Name: cmd.exe ID:13664 03/16/2021 05:20 PM | Process Name: conhost.exe ID:156 03/16/2021 05:20 PM | Process Name: cmd.exe ID:25108 03/16/2021 05:20 PM | Process Name: conhost.exe ID:8120 03/16/2021 05:20 PM | Process Name: Snipping Tool.e ID:12624 03/16/2021 05:20 PMI Process Name: chrome.exe ID:10672 03/16/2021 05:20 PM Process Name: chrome.exe ID:24092 03/16/2021 05:20 PM | Process Name: chrome.exe ID:17180 03/16/2021 05:20 PM | Process Name: chrome.exe ID:24788 03/16/2021 05:20 PM | Process Name: chrome.exe ID:1068 03/16/2021 05:20 PM | Process Name: chrome.exe ID:8376 03/16/2021 05:20 PM | Process Name: chrome.exe ID:9016 03/16/2021 05:20 PM | Process Name: chrome.exe ID:14228 03/16/2021 05:20 PMI Process Name: chrome.exe ID:9704 03/16/2021 05:20 PMI Process Name: chrome.exe ID:24672 b Form1 x 03/16/2021 05:20 PM | Process Name: cmd.exe ID:6672 03/16/2021 05:20 PM I Process Name: conhost.exe ID:18960 03/16/2021 05:20 PM | Process Name: cmd.exe ID:9436 03/16/2021 05:20 PM | Process Name: conhost.exe ID:8900 03/16/2021 05:20 PMI Process Name: cmd.exe ID:23576 03/16/2021 05:20 PM | Process Name: conhost.exe ID:16672 03/16/2021 05:20 PM | Process Name: cmd.exe ID:16044 03/16/2021 05:20 PM | Process Name: conhost.exe ID:20584 03/16/2021 05:20 PMI Process Name: cmd.exe ID:13664 03/16/2021 05:20 PM I Process Name: conhost.exe ID:156 03/16/2021 05:20 PM Process Name: cmd.exe ID:25108 03/16/2021 05:20 PM | Process Name: conhost.exe ID:8120 03/16/2021 05:20 PM I Process Name: SnippingTool.exe ID:12624 03/16/2021 05:20 PM | Process Name: chrome.exe ID:9704 03/16/2021 05:20 PMI Process Name: chrome.exe ID:24672 03/16/2021 05:20 PMI Process Name: chrome.exe ID:14228 03/16/2021 05:20 PM | Process Name: chrome.exe ID:8376 03/16/2021 05:20 PM 1 Process Name: chrome.exe ID:9016 03/16/2021 05:20 PM | Process Name: chrome.exe ID:24092 03/16/2021 05:20 PMI Process Name: chrome.exe ID:17180 03/16/2021 05:20 PMI Process Name: chrome.exe ID:10672 03/16/2021 05:20 PM | Process Name: chrome.exe ID:1068 03/16/2021 05:20 PMI Process Name: chrome.exe ID:24788 03/16/2021 05:21 PMI Process Name: SnippingTool.exe ID:1508 03/16/2021 05:20 PMI Process Name: conhost.exe ID:20592 03/16/2021 05:20 PM | Process Name: cmd.exe ID:6672 03/16/2021 05:20 PM | Process Name: conhost.exe ID:18960 03/16/2021 05:20 PM | Process Name: cmd.exe ID:9436 03/16/2021 05:20 PM | Process Name: conhost.exe ID:8900 03/16/2021 05:20 PM | Process Name: cmd.exe ID:23576 03/16/2021 05:20 PM | Process Name: conhost.exe ID: 16672 03/16/2021 05:20 PM | Process Name: cmd.exe ID:16044 03/16/2021 05:20 PM 1 Process Name: conhost.exe ID:20584 03/16/2021 05:20 PM I Process Name: cmd.exe ID:13664 03/16/2021 05:20 PM | Process Name: conhost.exe ID:156 03/16/2021 05:20 PM | Process Name: cmd.exe ID:25108 03/16/2021 05:20 PM | Process Name: conhost.exe ID:8120 03/16/2021 05:20 PM | Process Name: Snipping Tool.e ID:12624 03/16/2021 05:20 PMI Process Name: chrome.exe ID:10672 03/16/2021 05:20 PM Process Name: chrome.exe ID:24092 03/16/2021 05:20 PM | Process Name: chrome.exe ID:17180 03/16/2021 05:20 PM | Process Name: chrome.exe ID:24788 03/16/2021 05:20 PM | Process Name: chrome.exe ID:1068 03/16/2021 05:20 PM | Process Name: chrome.exe ID:8376 03/16/2021 05:20 PM | Process Name: chrome.exe ID:9016 03/16/2021 05:20 PM | Process Name: chrome.exe ID:14228 03/16/2021 05:20 PMI Process Name: chrome.exe ID:9704 03/16/2021 05:20 PMI Process Name: chrome.exe ID:24672

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

=+ what roles should government play in them ?

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago