Click to See Complete Forum and Search --> : Closing external applications


Hendo
November 18th, 2007, 02:36 PM
Hey, I have successfully run an external application with the Process class, but I can't seem to use the close method. If I use:
Process.Start(@"C:\WINDOWS\system32\calc.exe");

I only get the option to start not to close, but it builds sucessfully.
If I use this:

Process myProcess;
myProcess.Start(@"C:\WINDOWS\system32\calc.exe");

I do get the Close method to use later, but it doesn't build, and I get this error:
Static member 'System.Diagnostics.Process.Start(string)' cannot be accessed with an instance reference; qualify it with a type name instead

Also I have added the System.Diagnostics namespace.

Any help is appreciated
Thanks

dglienna
November 18th, 2007, 02:44 PM
from MSDN

private void ButtonStop_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process[] myProcesses;
myProcesses =
System.Diagnostics.Process.GetProcessesByName("Notepad");
foreach (System.Diagnostics.Process instance in myProcesses)
{
instance.CloseMainWindow();
instance.Close();
}
}

Hendo
November 18th, 2007, 02:45 PM
Yeh it wouldn't seem to build without it, if I left it out, I just got 3 "Unrecognized escape sequence" errors on the 3 letters of the file path

Hendo
November 18th, 2007, 02:51 PM
from MSDN

private void ButtonStop_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process[] myProcesses;
myProcesses =
System.Diagnostics.Process.GetProcessesByName("Notepad");
foreach (System.Diagnostics.Process instance in myProcesses)
{
instance.CloseMainWindow();
instance.Close();
}
}



Perfect! :D Thank you for the help!