question

MiPakTeh-6272 avatar image
0 Votes"
MiPakTeh-6272 asked TimonYang-MSFT commented

Application start Running

Hi All,

What try to do;

I have 2 Application. First App is "_Exe" and Second App is "Third". I need the program "_Exe" monitor the program "Third"
IF program "Third" start then "_Exe" raise a message" Program is Running now".
May be the program "_Exe" always running??.how to prepare the code like that.

Here some trial but I don't excatly to do.

Thank.

 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Diagnostics;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
    
 namespace _Exe
 {
     public partial class Form1 : Form
     {
         public Form1()
         {
             InitializeComponent();
    
    
         }
         public bool IsProcessOpen(string name)
         {
             foreach (Process clsProcess in Process.GetProcesses())
             {
                 if (clsProcess.ProcessName.ToLower().Contains(name.ToLower()))
                 {
                     return true;
                 }
             }
             return false;
         }
         private void Form1_Load(object sender, EventArgs e)
         {
             Process thisProc = Process.GetCurrentProcess();
             if (IsProcessOpen(name : "Third"))
             {
                 MessageBox.Show("Program is Running now");
             }
             else
             {
                 //MessageBox.Show("Not Run");
             }
         }
    
     }
 }
dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
0 Votes"
Castorix31 answered TimonYang-MSFT commented

To detect when a .exe is started, an usual way is with ManagementEventWatcher
(many other samples on Google, like Using WMI to monitor process creation, deletion and modification in .NET)


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I noticed that you posted a new question about this, please check my reply in that thread.

0 Votes 0 ·