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

  • SEARCH
  • Home
  • 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 7187451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:50:52+00:00 2026-05-28T18:50:52+00:00

I want to develop a windows application that will monitor whether a program has

  • 0

I want to develop a windows application that will monitor whether a program has started (lets say windows calculator) and time for how much time it has been used. I know I could poll the process to see whether it is on but I am not sure that this is the best solution.

I was considering global system hooks but after looking for hours I ended up more confused than from when I started. Are there any pointers towards any tutorials on how to do what I want or just some ideas. Is this something that needs global hooks or something else is better?

I don’t mind using either C# or C++ so please feel free point out to any relevant tutorials or documentation for either.

Thanks

  • 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-28T18:50:53+00:00Added an answer on May 28, 2026 at 6:50 pm

    Check process info (using polling)

    Process [] processes = Process.GetProcessesByName("notepad");
    if(processes.Length > 0)
       processes[0].StartTime;
    

    Register an event using native Windows (WMI) APIs:

    using System;
    using System.ComponentModel;
    using System.Collections;
    using System.Globalization;
    using System.Management;
    
    namespace WMI.Win32
    {
        public delegate void ProcessEventHandler(Win32_Process proc);
        public class ProcessWatcher : ManagementEventWatcher
        {
            // Process Events
            public event ProcessEventHandler ProcessCreated;
            public event ProcessEventHandler ProcessDeleted;
            public event ProcessEventHandler ProcessModified;
    
            // WMI WQL process query strings
            static readonly string WMI_OPER_EVENT_QUERY = @"SELECT * FROM 
    __InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'";
            static readonly string WMI_OPER_EVENT_QUERY_WITH_PROC =
                WMI_OPER_EVENT_QUERY + " and TargetInstance.Name = '{0}'";
    
            public ProcessWatcher()
            {
                Init(string.Empty);
            }
            public ProcessWatcher(string processName)
            {
                Init(processName);
            }
            private void Init(string processName)
            {
                this.Query.QueryLanguage = "WQL";
                if (string.IsNullOrEmpty(processName))
                {
                    this.Query.QueryString = WMI_OPER_EVENT_QUERY;
                }
                else
                {
                    this.Query.QueryString =
                        string.Format(WMI_OPER_EVENT_QUERY_WITH_PROC, processName);
                }
    
                this.EventArrived += new EventArrivedEventHandler(watcher_EventArrived);
            }
            private void watcher_EventArrived(object sender, EventArrivedEventArgs e)
            {
                string eventType = e.NewEvent.ClassPath.ClassName;
                Win32_Process proc = new 
                    Win32_Process(e.NewEvent["TargetInstance"] as ManagementBaseObject);
    
                switch (eventType)
                {
                    case "__InstanceCreationEvent":
                        if (ProcessCreated != null) ProcessCreated(proc); break;
                    case "__InstanceDeletionEvent":
                        if (ProcessDeleted != null) ProcessDeleted(proc); break;
                    case "__InstanceModificationEvent":
                        if (ProcessModified != null) ProcessModified(proc); break;
                }
            }
        }
    
        // Auto-Generated running: mgmtclassgen Win32_Process /n root\cimv2 /o WMI.Win32
        // Renaming the class from Process to Win32_Process
        public class Win32_Process { ... }
    }
    
    // Sample Usage
    ProcessWatcher procWatcher = new ProcessWatcher("notepad.exe");
    procWatcher.ProcessCreated += new ProcessEventHandler(procWatcher_ProcessCreated);
    procWatcher.ProcessDeleted += new ProcessEventHandler(procWatcher_ProcessDeleted);
    procWatcher.ProcessModified += new ProcessEventHandler(procWatcher_ProcessModified);
    procWatcher.Start();
    
    // Do Work
    
    procWatcher.Stop();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to develop a windows application. If I use native C++ and MFC
I want to develop a photo browser application in Windows platfrom, the UI should
I want to develop windows service in Delphi that communicates with an Oracle server
I want to develop a mobile web application using asp.net 3.5 that can be
Looking to develop server-side application that will process documents. The source documents are mostly
I want to write application on android and windows which will use bluetooth. In
I've been asked to develop a new application that will work along side the
My team is planning to develop an application that is initially targeted for Windows
I want to develop Windows WPF application using Kinect with great GUI/NUI. I've found
I want to develop an Java application that can detect the user logged on

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.