how to find list of all the url tabs of IE presently running (multiple tabs) its name as application for each find cpu usage?

Nov 12 2009 12:58 PM
HI,
I am trying to find cpu usage or total processor time of each tab of IE. I am able to just list one main url in the list of application. I am able to list all the url using shdocvw but for that url, I am not able to find totalprocessortime and also for each cpuusage, as i am trying to find the power consumed by each url tab individually,can any body help me on it.

The code i have written is  as follows:
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using SHDocVw;
using System.Diagnostics;
//using System.ComponentModel; :)
//using System.Threading;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;


namespace monitor_18_10
{
    
    class Program
    {
        

        static void Main(string[] args)
        {

           // FileStream file1 = new FileStream("d:\\class\\log.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            FileStream file1 = new FileStream("d:\\class\\yyyn.txt", FileMode.Create, FileAccess.ReadWrite);
            StreamWriter sw1 = new StreamWriter(file1);
            FileStream file2 = new FileStream("d:\\class\\log4.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            StreamWriter sw2 = new StreamWriter(file1);
            Process[] allProcs = Process.GetProcesses();

            foreach (Process thisProc in allProcs)
            {
                //if (!thisProc.HasExited)
                //{
                // thisProc.Refresh();

                string procName = thisProc.ProcessName;
                //string totproc = thisProc.TotalProcessorTime.ToString();


                int procID = thisProc.Id;

                // string totproc=thisProc.TotalProcessorTime.ToString();
                //string su=thisProc.StartTime.ToShortTimeString ();

                //string su=thisProc.StartTime.ToString ();
                //string su = proctime.ToString();

                string s = procID.ToString();
                string ss = procName.ToString();
                //  string sss = totproc.ToString();



               // richTextBox1.AppendText(s + "\t" + ss + "\n");
               Console .WriteLine (s + "\t" + ss + "\n");
               sw1.WriteLine(s + "\t" + ss + "\n");

               
                //}
            }
           sw1.WriteLine("-------------------------------------------------");
            Console.WriteLine("-------------------------------------------------");
            foreach (Process p in Process.GetProcesses("."))
            {

                try
                //{do
                {


                    // if(!p.HasExited )
                    // {
                    // p.Refresh ();

                    if (p.MainWindowTitle.Length > 0)
                    {
                        Console.Write("");
                        string s2;
                        string s3;
                        string pt;
                        s2 = p.MainWindowTitle.ToString();
                        s3 = p.StartTime.ToString();
                        pt = p.TotalProcessorTime.ToString();

                        //richTextBox2.AppendText(s2 + "\t" + s3 + "\t" + pt + "\n\n\n");
                        //richTextBox4.AppendText(s3 + "\n\n\n");

                        Console .WriteLine (s2 + "\t" + s3 + "\t" + pt + "\n");
                        Console.WriteLine(s3 + "\n\n\n");
                        sw1.WriteLine(s2 + "\t\t\t" + s3 + "\t\t\t" + pt + "\n\n\n");
                        //sw1.WriteLine(s3 + "\n\n\n");
                        //}
                    }
                   
                    //} while (!p.WaitForExit(1000));
                }
                catch { }



            }
            Console.WriteLine("-------------------------------------------------");
            sw1.WriteLine("-------------------------------------------------");
            /// cpu usage of each processes
            foreach (Process proc in Process.GetProcesses())
            {
                using (PerformanceCounter pcProcess = new PerformanceCounter("Process", "% Processor Time", proc.ProcessName))
                {
                    pcProcess.NextValue();
                    //System.Threading.Thread.Sleep(1000);
                    // Console.WriteLine("Process:{0} CPU% {1}", proc.ProcessName, pcProcess.NextValue());
                    string cpuname = proc.ProcessName.ToString();
                    string pcprocess = (pcProcess.NextValue() / 100).ToString();

                    //richTextBox5.AppendText(cpuname + "\t" + pcprocess + "\n");
                    Console.WriteLine(cpuname + "\t" + pcprocess + "\n");
                    sw1.WriteLine(cpuname + "\t" + pcprocess + "\n");
                   
                }
            }

            Console.WriteLine("-------------------------------------------------");
            sw1.WriteLine("-------------------------------------------------");
            ///reading excel data
            ///
            StreamReader SR;
            string S;
            int i = 0;
            SR = File.OpenText(@"d:\\class\\WR111.xls");

            S = SR.ReadToEnd();
            SR.Close();
            Console.WriteLine(S);
            string[] words = S.Split(';');
            Array.Sort(words);
            for (i = 0; i < words.Length; i++)
                Console.WriteLine(words[i]);

            //this will create the archive
            //StreamWriter SW;
            //SW = File.CreateText(@"d:\\class\\data2.txt");
            for (i = 0; i < words.Length; i++)
                sw1.WriteLine(words[i]);
            //SW.Close();

            //reading excel data ends here
            /// cpu usage ends here
            

            // --------------------------------------------------------------------
            // List of application processes
            // --------------------------------------------------------------------
            string processName;
            ShellWindows SW = new ShellWindowsClass();

            foreach (SHDocVw.WebBrowser IE in SW)
            {

                processName = System.IO.Path.GetFileNameWithoutExtension(IE.FullName).ToLower();

                string s4 = processName;

                //Console.WriteLine(processName);
                sw1.WriteLine(processName);

                if (processName.Equals("iexplore"))
                {
                    string s5 = IE.LocationURL.ToString();
                    sw1.WriteLine(s5);
                    Console.WriteLine(IE.LocationURL);
                    sw1.WriteLine(IE.LocationURL);
                    String s1 = ReadUrl(IE.LocationURL);
                    //richTextBox3.AppendText(IE.LocationURL + "\n");
                    Console.WriteLine(IE.LocationURL + "\n");
                    sw1.WriteLine(IE.LocationURL + "hello"+"\n");
                    Console.WriteLine("hi y this stupid is not running");
                    sw1.WriteLine(IE.LocationURL + "\n");
                    sw1.WriteLine("hi y this stupid is not running");
                  
                    sw2.WriteLine(IE.LocationURL + "\n");

                    //Console.WriteLine(s1);
                    bool m;

                    if (m = s1.Contains(".aac"))

                        //Console.WriteLine("it contains audio");
                        sw1.WriteLine("it contains audio");

                    else if (m = s1.Contains(".aif"))

                        sw1.WriteLine("it contains audio");
                    else if (m = s1.Contains(".iff"))
                        sw1.WriteLine("it contains audio");
                    else if (m = s1.Contains(".m3u"))
                        sw1.WriteLine("it contains audio");
                    else if (m = s1.Contains(".mid"))
                        sw1.WriteLine("it contains audio");
                    else if (m = s1.Contains(".midi"))
                        sw1.WriteLine("it contains audio");
                    else if (m = s1.Contains(".mp3"))
                        sw1.WriteLine("it contains audio");
                    else if (m = s1.Contains(".mpa"))
                        sw1.WriteLine("it contains audio");
                    else if (m = s1.Contains(".wav"))
                        sw1.WriteLine("it contains audio");
                    else if (m = s1.Contains(".wma"))
                        sw1.WriteLine("it contains audio");
                    else if (m = s1.Contains(".3g2"))
                        sw1.WriteLine("it contains video");
                    else if (m = s1.Contains(".3gp"))
                        sw1.WriteLine("it contains video");
                    else if (m = s1.Contains(".asf"))
                        sw1.WriteLine("it contains video");
                    else if (m = s1.Contains(".asx"))
                        sw1.WriteLine("it contains video");
                    else if (m = s1.Contains(".avi"))
                        sw1.WriteLine("it contains video");
                    else if (m = s1.Contains(".flv"))
                        sw1.WriteLine("it contains video");
                    else if (m = s1.Contains(".mkv"))
                        sw1.WriteLine("it contains video");
                    else if (m = s1.Contains(".mov"))
                        sw1.WriteLine("it contains video");
                    else if (m = s1.Contains(".mp4"))
                        sw1.WriteLine("it contains video");
                    else if (m = s1.Contains(".mpg"))
                        sw1.WriteLine("it contains video");
                    else if (m = s1.Contains(".qt"))
                        sw1.WriteLine("it contains video");
                    else if (m = s1.Contains(".rm"))
                        sw1.WriteLine("it contains video");
                    else if (m = s1.Contains(".swf"))
                        sw1.WriteLine("it contains video");
                    else if (m = s1.Contains(".vob"))
                        sw1.WriteLine("it contains video");
                    else if (m = s1.Contains(".wmv"))
                        sw1.WriteLine("it contains video");
                    else
                        sw1.WriteLine("no audio or video in the file");




                    string type = ExtractApplicationType(s1);

                    if (type.CompareTo("vedio") == 0)
                    {
                        sw1.WriteLine("Running Vedio application");

                    }
                    else
                    {
                        sw1.WriteLine("Running text application");
                    }

                }





                

                //this.Refresh();

            }
            //reading data from the meter
            //readexceldata();
            sw1.Close();
        }

        static string ReadUrl(string url)

        {
            //FileStream file2 = new FileStream("d:\\class\\log2.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            //StreamWriter sw2 = new StreamWriter(file2);
            Uri uri = new Uri(url);
            //sw2.WriteLine("hi");
            //sw2.WriteLine(url);
            //Create the request object
            WebRequest req = WebRequest.Create(uri);
           
            WebResponse resp = req.GetResponse();
            Stream stream = resp.GetResponseStream();
            StreamReader sr = new StreamReader(stream);

            string sss = sr.ReadToEnd();
            //string sss = uri.ToString();

            return (sss);

        }
       //public static void readexceldata()
       // {
       //     StreamReader SR;
       //     string S;
       //     int i = 0;
       //     SR = File.OpenText(@"d:\\class\\WR111.xls");

       //     S = SR.ReadToEnd();
       //     SR.Close();
       //     Console.WriteLine(S);
       //     string[] words = S.Split(';');
       //     Array.Sort(words);
       //     for (i = 0; i < words.Length; i++)
       //         Console.WriteLine(words[i]);

       //     //this will create the archive
       //     StreamWriter SW;
       //     SW = File.AppendText(@"d:\\class\\yyy.txt");
       //     for (i = 0; i < words.Length; i++)
       //         SW.WriteLine(words[i]);
       //     SW.Close();

       // }
        static string ExtractApplicationType(string s)
        {

            // Line like: "Last</TD><TD ALIGN=RIGHT NOWRAP><B> 78 3/16"
            // Line Like embed src
            string sPattern = "application/x-shockwave-flash";
            if (System.Text.RegularExpressions.Regex.IsMatch(s, sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
            {
                // richTextBox3.AppendText("  (match for '{0}' found)", sPattern);
                return "vedio";
            }
            else
            {
                return "text";
            }
            // return "text";
        }



    }
}




Hope to  get reply,

thanks in advance...


Cheers..
Namrata :)
<code></code><big></big>