473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 4912
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: David Leon | last post by:
Is there any way to stop php.exe closing after it processes a PHP script? It doesn't seem to have the traditional options of an MS-DOS program. I am using Windows XP Pro and have associated .php...
6
by: Henrik Holm | last post by:
I have recently started playing around with Python. Some of the things I have done have involved reading files. The way I do this is along the lines of f = file('file.txt') lines =...
7
by: Johnny | last post by:
How do I create a link on a Web page on my hard drive that will run an executable file on my hard drive? For example, let's say I create runpoodle.htm and save it to my hard drive, and let's...
0
by: Tam | last post by:
I have a problem trying to close a currently running executable. javaw.exe simply refuses to close. It is in the process list (confirmed by watching Processes in the task manager) and the code...
6
by: foldface | last post by:
Hi Sorry, don't know how to phrase the question any better. Within Visual Studio I have a style sheet that being dynamically added to the code, i.e. not via the html page. I want to place this...
17
by: Csaba Gabor | last post by:
Is there a way to determine the path to the php executable (as opposed to the script. In other words, I am looking for the path to php.exe or php-win.exe) that is currently running (ie. how was...
10
by: jon | last post by:
I am a beginner C programmer, this is actually my first programming lanugage, besides html, cgi, and javascript. I am looking for a way to make an .exe file, or a copy of my own file. I have tried...
4
by: Brad Pears | last post by:
I have a vb.net 2005 project and have made a lot of modifications to it. The project runs fine in debug mode. Now I want to implement it and first I am running the executable on my machine to make...
4
by: Perl Beginner | last post by:
Hello, I have written a VB program (VB 6.0) that is basically a GUI for the user to select from various buttons to run other executable files (which I wrote in Perl). When the Perl executable is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.