Closing another program in C#
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Closing another program in C#

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Posts
    2

    Closing another program in C#

    I would like to know how I can create a program in visual c# 2008 that closes another program, such as word, when the user presses the middle mouse button.

  2. #2
    Join Date
    Jul 2006
    Posts
    297

    Re: Closing another program in C#

    http://msdn.microsoft.com/en-us/libr...ainwindow.aspx
    and
    http://msdn.microsoft.com/en-us/library/z3w4xdc9.aspx

    Code:
                Process[] processes = Process.GetProcessesByName("notepad");
    
                foreach (Process p in processes)
                {
                    p.CloseMainWindow();
                    p.WaitForExit();
                }

  3. #3
    Join Date
    Jul 2009
    Posts
    2

    Re: Closing another program in C#

    That worked perfectly, thank you.

  4. #4
    Join Date
    Jul 2006
    Posts
    297

    Re: Closing another program in C#

    Sorry didn't read the whole question... Here ya go

    Code:
            public Form1()
            {
                this.MouseDown += new MouseEventHandler(form_MouseDown);
            }
    
            public void CloseProcesses()
            {
                Process[] processes = Process.GetProcessesByName("notepad");
    
                foreach (Process p in processes)
                {
                    p.CloseMainWindow();
                    p.WaitForExit();
                }
            }
    
            private void form_MouseDown(Object sender, MouseEventArgs e)
            {
                switch (e.Button)
                {
                    case MouseButtons.Middle:
                        CloseProcesses();
                        break;
                }
            }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center