Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7058055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:04:02+00:00 2026-05-28T04:04:02+00:00

I am writing a program that must register time of starting a process such

  • 0

I am writing a program that must register time of starting a process such as notepad.
I thought that it is good to create a Timer that checks all of processes every second. But I think that it will slow down the user’s computer. Is there a better way of doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:04:02+00:00Added an answer on May 28, 2026 at 4:04 am

    Initially determine for all running processes the creation time. Then
    use WMI to register for process creation events.

    See the code below for a small example on how to use WMI for process creation events:

    static void Main(string[] args)
    {
      using (ManagementEventWatcher eventWatcher =
                new ManagementEventWatcher(@"SELECT * FROM 
       __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'"))
      {
        // Subscribe for process creation notification.
        eventWatcher.EventArrived += ProcessStarted_EventArrived; 
        eventWatcher.Start();
        Console.In.ReadLine();
        eventWatcher.EventArrived -= ProcessStarted_EventArrived;
        eventWatcher.Stop();
      }
    }
    
    
    static void ProcessStarted_EventArrived(object sender, EventArrivedEventArgs e)
    {
      ManagementBaseObject obj = e.NewEvent["TargetInstance"] as ManagementBaseObject;
    
      // The Win32_Process class also contains a CreationDate property.
      Console.Out.WriteLine("ProcessName: {0} " + obj.Properties["Name"].Value);
    }
    

    BEGIN EDIT:

    I’ve further investigated process creation detection with WMI and there is a (more) resouces friendly solution (but needs administrative privileges) using the Win32_ProcessStartTrace class (please see TECHNET for further information):

    using (ManagementEventWatcher eventWatcher =
              new ManagementEventWatcher(@"SELECT * FROM Win32_ProcessStartTrace"))
    {
      // Subscribe for process creation notification.
      eventWatcher.EventArrived += ProcessStarted_EventArrived;
      eventWatcher.Start();
      Console.Out.WriteLine("started");
      Console.In.ReadLine();
      eventWatcher.EventArrived -= ProcessStarted_EventArrived;
      eventWatcher.Stop();
    }
    
    static void ProcessStarted_EventArrived(object sender, EventArrivedEventArgs e)
    {               
      Console.Out.WriteLine("ProcessName: {0} " 
              + e.NewEvent.Properties["ProcessName"].Value);     
    }
    

    In this solution you do not have to set an polling interval.

    END EDIT

    BEGIN EDIT 2:

    You could use the Win32_ProcessStopTrace class to monitor process stop events. To combine both process start and process stop events use the Win32_ProcessTrace class. In the event handler use the ClassPath proberty to distinguish between start/stop events:

    using (ManagementEventWatcher eventWatcher =
           new ManagementEventWatcher(@"SELECT * FROM Win32_ProcessTrace"))
    {          
      eventWatcher.EventArrived += Process_EventArrived;
      eventWatcher.Start();
      Console.Out.WriteLine("started");
      Console.In.ReadLine();
      eventWatcher.EventArrived -= Process_EventArrived;
      eventWatcher.Stop();
    }
    
    static void Process_EventArrived(object sender, EventArrivedEventArgs e)
    {
      Console.Out.WriteLine(e.NewEvent.ClassPath); // Use class path to distinguish
                                                   // between start/stop process events.
      Console.Out.WriteLine("ProcessName: {0} " 
          + e.NewEvent.Properties["ProcessName"].Value);     
    }
    

    END EDIT 2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a shell program that must handle signals. My relevant signal handling related
A requirement for a program I am writing is that it must be able
I am writing a program that must communicate with a PHP / web based
I’m writing a small C program that must accept an input stream larger than
Currently I am writing a program that must iterate through and arraylist inside of
Im writing a program that should read input via stdin, so I have the
I'm writing a program that sends an email out at a client's specific local
If you are writing a program that is executable from the command line, you
I'm writing a program that uses SetWindowRgn to make transparent holes in a window
I'm writing a program that contains a generational garbage collector. There are just two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.