Beispiel #1
0
        void pm_ProcessStart(object sender, ProcessMonitorEventArgs e)
        {
            switch (e.ProcessName)
            {
            case "WINWORD.EXE":
                if (e.Arguments != null && e.ActiveAppTitle != null)
                {
                    string          fname = e.ActiveAppTitle;
                    OpenedEventArgs foe   = new OpenedEventArgs(fname);
                    if (FSMOpened != null)
                    {
                        FSMOpened(this, foe);
                    }
                }
                break;

            case "AcroRd32.exe":
                if (e.Arguments != null && e.Arguments.Contains(".pdf"))
                {
                    string[] args = e.Arguments.Split(new string[] { "\" \"" }, StringSplitOptions.RemoveEmptyEntries);
                    if (args.Length == 2)
                    {
                        string          fname = args[1];
                        OpenedEventArgs foea  = new OpenedEventArgs(fname);
                        if (FSMOpened != null)
                        {
                            FSMOpened(this, foea);
                        }
                        break;
                    }
                }
                break;
            }
        }
Beispiel #2
0
        void ThStartMethod()
        {
            // Block until the next event occurs
            // Note: this can be done in a loop if waiting for more than one occurrence
            ManagementBaseObject mbo = watcher.WaitForNextEvent();

            // Wait for UI application (if any) to open
            // so we can get its title
            Thread.Sleep(500);
            UInt32 pid = UInt32.Parse((((ManagementBaseObject)mbo["TargetInstance"])["ProcessId"]).ToString());
            string aat = new string(' ', 100);

            if (pid == WinAPI.GetWindowProcessID(WinAPI.GetForegroundWindow()))
            {
                aat = WinAPI.ActiveApplTitle();
            }
            else
            {
                aat = null;
            }
            ProcessMonitorEventArgs e = new ProcessMonitorEventArgs(((ManagementBaseObject)mbo["TargetInstance"])["Name"],
                                                                    ((ManagementBaseObject)mbo["TargetInstance"])["ExecutablePath"], pid,
                                                                    ((ManagementBaseObject)mbo["TargetInstance"])["CommandLine"], aat);

            // Rise ProcessStart event
            if (ProcessStart != null)
            {
                ProcessStart(this, e);
            }
            ThStartMethod();
        }