469,927 Members | 1,803 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Closing a running executable

mg
System.Diagnostics.Process.Start("c:\\windows\\sys tem32\\notepad.exe","c:\\x.txt");

launches x.txt in notepad

What code will close this instance of notepad?

Nov 16 '05 #1
5 4672
Hi!

"mg" schrieb
System.Diagnostics.Process.Start("c:\\windows\\sys tem32\\notepad.exe","c:\\x.txt");
launches x.txt in notepad
What code will close this instance of notepad?


//You need a reference to the process
Process p = new Process();
ProcessStartInfo psi =
new ProcessStartInfo(
"c:\\windows\\system32\\notepad.exe");
p.StartInfo = psi;

//Start notepad
p.Start();

//Sleep five seconds
System.Threading.Thread.Sleep(5000);

//Close notepad again
p.CloseMainWindow();

Cheers

Arne Janning
Nov 16 '05 #2
mg
The following code opens a text file in notepad and then closes notepad ...
as desired.

System.Diagnostics.Process p = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo psi = new
System.Diagnostics.ProcessStartInfo("c:\\windows\\ system32\\notepad.exe","c:\\x.txt");
p.StartInfo = psi;
p.Start();
p.CloseMainWindow();
But, the following code opens a pdf file in the Acrobat reader but then does
not close the Acrobat reader.

System.Diagnostics.Process p = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo psi = new
System.Diagnostics.ProcessStartInfo("c:\\program files\\adobe\\acrobat
6.0\\reader\\acrord32.exe",@"/t ""c:\exportfiles\d.pdf"" ""HP LaserJet 3300
Series PCL 6"" ""HP LaserJet 3300 Series PCL 6"" ""DOT4_001""");
p.StartInfo = psi;
p.Start();
p.CloseMainWindow();

How can I close this Acrobat reader programatically?
"Arne Janning" wrote:
Hi!

"mg" schrieb
System.Diagnostics.Process.Start("c:\\windows\\sys tem32\\notepad.exe","c:\\x.txt");
launches x.txt in notepad
What code will close this instance of notepad?


//You need a reference to the process
Process p = new Process();
ProcessStartInfo psi =
new ProcessStartInfo(
"c:\\windows\\system32\\notepad.exe");
p.StartInfo = psi;

//Start notepad
p.Start();

//Sleep five seconds
System.Threading.Thread.Sleep(5000);

//Close notepad again
p.CloseMainWindow();

Cheers

Arne Janning

Nov 16 '05 #3
mg
The following code opens a text file in notepad and then closes notepad ...
as desired.

System.Diagnostics.Process p = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo psi = new
System.Diagnostics.ProcessStartInfo("c:\\windows\\ system32\\notepad.exe","c:\\x.txt");
p.StartInfo = psi;
p.Start();
p.CloseMainWindow();
But, the following code opens a pdf file in the Acrobat reader but then does
not close the Acrobat reader.

System.Diagnostics.Process p = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo psi = new
System.Diagnostics.ProcessStartInfo("c:\\program files\\adobe\\acrobat
6.0\\reader\\acrord32.exe",@"/t ""c:\exportfiles\d.pdf"" ""HP LaserJet 3300
Series PCL 6"" ""HP LaserJet 3300 Series PCL 6"" ""DOT4_001""");
p.StartInfo = psi;
p.Start();
p.CloseMainWindow();

How can I close this Acrobat reader programatically?
"Arne Janning" wrote:
Hi!

"mg" schrieb
System.Diagnostics.Process.Start("c:\\windows\\sys tem32\\notepad.exe","c:\\x.txt");
launches x.txt in notepad
What code will close this instance of notepad?


//You need a reference to the process
Process p = new Process();
ProcessStartInfo psi =
new ProcessStartInfo(
"c:\\windows\\system32\\notepad.exe");
p.StartInfo = psi;

//Start notepad
p.Start();

//Sleep five seconds
System.Threading.Thread.Sleep(5000);

//Close notepad again
p.CloseMainWindow();

Cheers

Arne Janning

Nov 16 '05 #4
If you look through the help on the System.Diagnostics.Process class, you'll
note that there are "Close()" and "Kill" methods, as well as
"WaitForExit()", etc. so "p.Kill()" will (rudely) kill the running process.

CloseMainWindow() sends the window an exit message, which is the nice way of
doing it with a windows executable. However, it may or may not behave the
way you want it to.

--
-Philip Rieck
http://philiprieck.com/blog/

-
"mg" <mg@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
The following code opens a text file in notepad and then closes notepad
...
as desired.

System.Diagnostics.Process p = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo psi = new
System.Diagnostics.ProcessStartInfo("c:\\windows\\ system32\\notepad.exe","c:\\x.txt");
p.StartInfo = psi;
p.Start();
p.CloseMainWindow();
But, the following code opens a pdf file in the Acrobat reader but then
does
not close the Acrobat reader.

System.Diagnostics.Process p = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo psi = new
System.Diagnostics.ProcessStartInfo("c:\\program files\\adobe\\acrobat
6.0\\reader\\acrord32.exe",@"/t ""c:\exportfiles\d.pdf"" ""HP LaserJet
3300
Series PCL 6"" ""HP LaserJet 3300 Series PCL 6"" ""DOT4_001""");
p.StartInfo = psi;
p.Start();
p.CloseMainWindow();

How can I close this Acrobat reader programatically?
"Arne Janning" wrote:
Hi!

"mg" schrieb
> System.Diagnostics.Process.Start("c:\\windows\\sys tem32\\notepad.exe","c:\\x.txt");
> launches x.txt in notepad
> What code will close this instance of notepad?


//You need a reference to the process
Process p = new Process();
ProcessStartInfo psi =
new ProcessStartInfo(
"c:\\windows\\system32\\notepad.exe");
p.StartInfo = psi;

//Start notepad
p.Start();

//Sleep five seconds
System.Threading.Thread.Sleep(5000);

//Close notepad again
p.CloseMainWindow();

Cheers

Arne Janning

Nov 16 '05 #5
If you look through the help on the System.Diagnostics.Process class, you'll
note that there are "Close()" and "Kill" methods, as well as
"WaitForExit()", etc. so "p.Kill()" will (rudely) kill the running process.

CloseMainWindow() sends the window an exit message, which is the nice way of
doing it with a windows executable. However, it may or may not behave the
way you want it to.

--
-Philip Rieck
http://philiprieck.com/blog/

-
"mg" <mg@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
The following code opens a text file in notepad and then closes notepad
...
as desired.

System.Diagnostics.Process p = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo psi = new
System.Diagnostics.ProcessStartInfo("c:\\windows\\ system32\\notepad.exe","c:\\x.txt");
p.StartInfo = psi;
p.Start();
p.CloseMainWindow();
But, the following code opens a pdf file in the Acrobat reader but then
does
not close the Acrobat reader.

System.Diagnostics.Process p = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo psi = new
System.Diagnostics.ProcessStartInfo("c:\\program files\\adobe\\acrobat
6.0\\reader\\acrord32.exe",@"/t ""c:\exportfiles\d.pdf"" ""HP LaserJet
3300
Series PCL 6"" ""HP LaserJet 3300 Series PCL 6"" ""DOT4_001""");
p.StartInfo = psi;
p.Start();
p.CloseMainWindow();

How can I close this Acrobat reader programatically?
"Arne Janning" wrote:
Hi!

"mg" schrieb
> System.Diagnostics.Process.Start("c:\\windows\\sys tem32\\notepad.exe","c:\\x.txt");
> launches x.txt in notepad
> What code will close this instance of notepad?


//You need a reference to the process
Process p = new Process();
ProcessStartInfo psi =
new ProcessStartInfo(
"c:\\windows\\system32\\notepad.exe");
p.StartInfo = psi;

//Start notepad
p.Start();

//Sleep five seconds
System.Threading.Thread.Sleep(5000);

//Close notepad again
p.CloseMainWindow();

Cheers

Arne Janning

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by David Leon | last post: by
6 posts views Thread by Henrik Holm | last post: by
7 posts views Thread by Johnny | last post: by
reply views Thread by Tam | last post: by
6 posts views Thread by foldface | last post: by
17 posts views Thread by Csaba Gabor | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.