Click here to Skip to main content
15,915,319 members
Home / Discussions / C#
   

C#

 
QuestionLocalization of data Pin
Herhighness29-Nov-06 7:24
Herhighness29-Nov-06 7:24 
AnswerRe: Localization of data Pin
dead_link29-Nov-06 8:10
dead_link29-Nov-06 8:10 
QuestionStrange reaction from a DataGridView Pin
~~~Johnny~~~29-Nov-06 7:05
~~~Johnny~~~29-Nov-06 7:05 
QuestionXmlDocument - Browser View Pin
h@s@n29-Nov-06 6:46
h@s@n29-Nov-06 6:46 
QuestionRe: XmlDocument - Browser View Pin
loneferret29-Nov-06 7:29
loneferret29-Nov-06 7:29 
AnswerRe: XmlDocument - Browser View Pin
h@s@n29-Nov-06 7:46
h@s@n29-Nov-06 7:46 
QuestionGet Current Process Pin
Now_Loading29-Nov-06 5:59
Now_Loading29-Nov-06 5:59 
AnswerRe: Get Current Process Pin
Eric Dahlvang29-Nov-06 6:45
Eric Dahlvang29-Nov-06 6:45 
To get all processes running on the local computer.
Process [] localAll = Process.GetProcesses();

Every running process is a current process. GetCurrentProcess retrieves whatever process the method is being run within. It sounds like what you really want to know is which application currently has the keyboard focus. For that you would use GetForegroundWindow (See: MSDN Forums-- Visual C#-- Visual C# General-- How do I determine which program window is active?[^])

However, if you are interested in currently running processes, you could use WMI to get a list, and notify you whenever a new process is created.
See this article: System.Management Lets You Take Advantage of WMI APIs within Managed Code[^]

using System;
using System.Management;

namespace WorkWithProcesses
{
    class Class1
    {
        static void Main(string[] args)
        {
            ManagementClass processClass = new ManagementClass
            (@"root\cimv2:Win32_Process");
            foreach (ManagementObject processInstance in 
            processClass.GetInstances())
            {
                Console.WriteLine(processInstance["Caption"].ToString());
            }

            //set up an event watcher and a handler for the process 
            //creation event
            ManagementEventWatcher watcher = new ManagementEventWatcher (
                new WqlEventQuery ("SELECT * FROM __InstanceCreationEvent 
                WITHIN 1 " +
                @"WHERE TargetInstance ISA ""Win32_Process"""));

            EventHandler handler = new EventHandler();
            watcher.EventArrived += new EventArrivedEventHandler
            (handler.Arrived);
            watcher.Start();    //start watching for events

            System.Threading.Thread.Sleep(180000); //wait for 3 minutes
            watcher.Stop();
            Console.WriteLine("Done watching for events");

        }
    }

    public class EventHandler
    {
        public void Arrived(object sender, EventArrivedEventArgs e)
        {
        Console.WriteLine("Process created  = " + 
        ((ManagementBaseObject)e.NewEvent["TargetInstance"])["Caption"]);
        }
    }

}


--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters

Questionis inaccessible due to its protection level Pin
dterry45829-Nov-06 5:28
dterry45829-Nov-06 5:28 
AnswerRe: is inaccessible due to its protection level Pin
BlaiseBraye29-Nov-06 7:16
BlaiseBraye29-Nov-06 7:16 
QuestionHow to Select Datagridview certain cell (Urgent) Pin
mohamedyahyaelzayat29-Nov-06 4:49
mohamedyahyaelzayat29-Nov-06 4:49 
AnswerRe: How to Select Datagridview certain cell (Urgent) Pin
ednrgc29-Nov-06 5:02
ednrgc29-Nov-06 5:02 
GeneralRe: How to Select Datagridview certain cell (Urgent) Pin
mohamedyahyaelzayat29-Nov-06 5:22
mohamedyahyaelzayat29-Nov-06 5:22 
GeneralRe: How to Select Datagridview certain cell (Urgent) Pin
ednrgc29-Nov-06 6:39
ednrgc29-Nov-06 6:39 
GeneralRe: How to Select Datagridview certain cell (Urgent) Pin
mohamedyahyaelzayat29-Nov-06 23:23
mohamedyahyaelzayat29-Nov-06 23:23 
AnswerRe: How to Select Datagridview certain cell (Urgent) Pin
Eric Dahlvang29-Nov-06 5:50
Eric Dahlvang29-Nov-06 5:50 
GeneralRe: How to Select Datagridview certain cell (Urgent) Pin
mohamedyahyaelzayat29-Nov-06 5:58
mohamedyahyaelzayat29-Nov-06 5:58 
QuestionDatabinding to a textbox (Urgent) Pin
Saira Tanwir29-Nov-06 3:51
Saira Tanwir29-Nov-06 3:51 
AnswerRe: Databinding to a textbox (Urgent) Pin
Eduard Keilholz29-Nov-06 4:10
Eduard Keilholz29-Nov-06 4:10 
GeneralRe: Databinding to a textbox (Urgent) Pin
Saira Tanwir29-Nov-06 4:22
Saira Tanwir29-Nov-06 4:22 
QuestionMy app works on the PC but not on the Smart Device - I'm desperate! Pin
Dewald29-Nov-06 3:49
Dewald29-Nov-06 3:49 
QuestionListView [Details View] Pin
h@s@n29-Nov-06 3:40
h@s@n29-Nov-06 3:40 
AnswerRe: ListView [Details View] Pin
dead_link29-Nov-06 6:50
dead_link29-Nov-06 6:50 
QuestionDisplaying Certain Folders & Subs in Treeview Pin
loneferret29-Nov-06 3:18
loneferret29-Nov-06 3:18 
AnswerRe: Displaying Certain Folders & Subs in Treeview Pin
Scott Dorman29-Nov-06 3:56
professionalScott Dorman29-Nov-06 3:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.