-
July 31st, 2009, 11:12 AM
#1
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.
-
July 31st, 2009, 11:55 AM
#2
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();
}
-
July 31st, 2009, 12:03 PM
#3
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;
}
}
-
July 31st, 2009, 12:11 PM
#4
Re: Closing another program in C#
That worked perfectly, thank you.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|