0

For example my application name is HardwareMonitoring So the process name should be HardwareMonitoring.exe

But what i see is HardwareMonitoring.vshost How can i make that it will show only names without the vshost in the end ?

void PopulateApplications()
        {

                int rcount = dataGridView1.Rows.Count;
                int rcurIndex = 0;
                foreach (Process p in Process.GetProcesses())
                {

                        try
                        {
                            if (File.Exists(p.MainModule.FileName))
                            {
                                if (p.MainModule.FileName.Contains("HardwareMonitoring"))
                                {
                                    MessageBox.Show("hi");
                                }
                                var icon = Icon.ExtractAssociatedIcon(p.MainModule.FileName);
                                Image ima = icon.ToBitmap();
                                ima = resizeImage(ima, new Size(25, 25));
                                ima = (Image)(new Bitmap(ima, new Size(25, 25)));

                                String status = p.Responding ? "Running" : "Not Responding";

                                if (rcurIndex < rcount - 1)
                                {
                                    dataGridView1.Rows[rcurIndex].Cells[0].Value = ima;
                                    dataGridView1.Rows[rcurIndex].Cells[1].Value = p.ProcessName;
                                    dataGridView1.Rows[rcurIndex].Cells[2].Value = status;
                                }
                                else
                                {
                                    dataGridView1.Rows.Add(ima, p.ProcessName, status);
                                }
                                rcurIndex++;

                            }
                        }
                        catch ( Exception e)
                        {
                            //string t = "error";
                        }

                }






                if (rcurIndex < rcount - 1)
                {
                    for (int i = rcurIndex; i < rcount - 1; i++)
                    {
                        dataGridView1.Rows.RemoveAt(rcurIndex);
                    }
                }


            int f = dataGridView1.Rows.GetRowsHeight(System.Windows.Forms.DataGridViewElementStates.None);
            firsttime += 1;
            if (firsttime == 1)
            {
                NumberOfRows = dataGridView1.Rows.Count;
            }
            if (NumberOfRows != dataGridView1.Rows.Count)
            {
                int diff = dataGridView1.Rows.Count - NumberOfRows;

                NumberOfRows = dataGridView1.Rows.Count;
            }



        }

It's adding the processes to the rows cells but it's adding vshost and not the regular exe file name. Instead adding HardwareMonitoring.vshost it should add only HardwareMonitoring

How can i fix it ?

user3681442
  • 297
  • 3
  • 15

1 Answers1

3

To fix this run your application directly from the windows explorer and not from Visual Studio. Simples :)

About the .vhost thing, please read this: http://blogs.msdn.com/b/dtemp/archive/2004/08/17/215764.aspx

HABJAN
  • 9,212
  • 3
  • 35
  • 59
  • Nope if i run it from the windows explorer it show also the vshost and also the regular exe. – user3681442 Jun 06 '14 at 10:19
  • @user3681442: First close Visual Studio, then open windows explorer and navigate to your bin folder. There you will see 2 exe files, one is your.exe the other is your.vhost.exe. You should run your.exe (the one you will probably deploy). your.vhost.exe is the one Visual Studio use for debugging purposes... – HABJAN Jun 06 '14 at 10:22
  • HABJAN ok . And how can i remove or not even get all this processes that are system processes ? like: dllhost or sqlwriter or dwm or nvvsvc. I want to get only apps that are running now like chrome skype apps like that. – user3681442 Jun 06 '14 at 10:27
  • @user3681442: by checking if the Main Window title is not empty. For instance: if (!string.IsNullOrEmpty(p.MainWindowTitle)) { addToList } – HABJAN Jun 06 '14 at 10:37