Important alert: (current site time 7/15/2013 8:08:39 AM EDT)
 

article

A__Start and End a Process__A

Email
Submitted on: 12/29/2003 6:42:01 PM
By: Yuri Vishnevsky  
Level: Intermediate
User Rating: By 5 Users
Compatibility: VB.NET
Views: 15369
 
     Have you ever wanted to end a program started by shell? This uses Process.Start and Process.Kill to start/stop processes, even ones you did not start.After reading this, you will also be able to Change the windowstyle, get the directroy, and many other things.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				1). Start a process:
Dim Prc() as Process
Prc(0) = Process.Start "C:\Windows\System32
\notepad.exe")
'replace the C:\Windows\System32
\notepad.exe with the path of the file you wish to open
2). To kill the process:
Prc(0).Kill()


To View Procesess Already Running

Dim Prc As Process
Dim x As Integer

Prc = Process.GetProcesses

For x = 0 To UBound(Prc())
Debug.WriteLine(Prc.ProcessName)
Next
To Kill A Process:
Prc(x).Kill
To change a windowstyle:
Prc (x).Startinfo.Windowstyle = whatever
to get the directory of the process:
use prc(x).startinfo.workingdirectory .


There are many other properties, most of
which seem self-explanatory like StartTime. playaround and enjoy!

p.S. and vote ;-P


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
12/29/2003 6:47:36 PM

Please Vote or Comment!
(If this comment was disrespectful, please report it.)

 
3/26/2004 1:07:47 PMDan Dayon

Small problem:

Dim Prc As Process
isn't an array.
It must be:
Dim Prc() As Process
(If this comment was disrespectful, please report it.)

 
6/14/2004 4:19:16 PM

Have you also taken this a step further and redirected both Standard In and Out? I need to send a return to the process after it starts and kill it with Ctrl-C. I will then need to read the Standard out. Here is the sample code I am using:
Dim ontapeProc = New Process()
With ontapeProc.StartInfo
.FileName = ontapeCmd
.Arguments = " -c "
.UseShellExecute = False
.RedirectStandardInput = True
.RedirectStandardOutput = True
End With
ontapeProc.EnableRaisingEvents = True
ontapeProc.Start()
Dim myStreamWriter As StreamWriter = ontapeProc.StandardInput
ontapeProc.WaitForExit(5000)
myStreamWriter.WriteLine(vbC rLf)
ontapeProc.WaitForExit(10000)
myStreamWriter.WriteLine("^(c)")

Thanks
for the help.
(If this comment was disrespectful, please report it.)

 
12/20/2004 10:19:44 AMilamgumaran

nice! i knew how to do it with vb and vc++ 6.0 but i was wondering how to do this in .net thanks. and sir i am a final year b.tech(IT) student. i am also doing a MCAD(.net) course and will write my MCP exams soon. will this be enough qualification to get a good IT job. please reply if you are free. sorry if i am bothering you. ilamgumaran
(If this comment was disrespectful, please report it.)

 
10/6/2005 4:53:17 AMHenry

wow, even though it's look like your code is to simple, but yet its add my knowledge about vb.net thanks yuri
(If this comment was disrespectful, please report it.)

 
8/26/2006 1:06:07 AMpedram

thanks a lot
(If this comment was disrespectful, please report it.)

 
2/24/2007 2:46:30 PM

thnx for ur code
(If this comment was disrespectful, please report it.)

 
3/22/2007 8:51:36 AMtri

terima kasih(thanks), yuri.....
(If this comment was disrespectful, please report it.)

 
2/28/2008 4:07:08 PMPSF

Five globes for you, thanks : )
Dim Prc As Process
Prc = Process.Start(cfg.item("http://www.altavista.com"))
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.