473,395 Members | 1,629 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,395 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 4911
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.