home *** CD-ROM | disk | FTP | other *** search
-
- <!-- #include virtual="/quickstart/howto/include/header.inc" -->
-
- <h4>How Do I...Start and stop a process?</h4>
-
- <div class="indent" style="width:660"><font face="Tahoma" size="1">
-
- <p>You can use the Process component to accomplish
- most process management tasks quickly and easily. You can use this component to
- work with processes on either local or remote computers. On a local computer,
- you can for example start and stop a process.</p>
-
- <p>This
- sample illustrates how to start and stop an executable. It's a small console application that can be run from a
- command prompt. The application takes one command line argument. The argument is
- a full path to the executable to be started. <b>Note</b>: this sample will only work on
- processes which have a window and wait for input. Using this sample on a process which does not meet
- these criteria will cause an exception to be thrown.</p>
-
- <p>For example, if you want to start and then stop Notepad, run
- the sample with the following command line argument:</p>
-
- </font><font face="Courier New" color="Blue" size="1"><blockquote>
- > ProcessDemo.exe c:\winnt\notepad.exe
- </blockquote></font><font face="Tahoma" size="1">
-
- <p>You will see a notepad being started and then closed after approximately 1 second.</p>
-
- <p>In its simplest form, starting a process involves:</p>
-
- <ol>
- <li>Instantiating a Process component and initializing the path to an executable:
-
- </font><font face="Courier New" color="Blue" size="1"><p>
- Process process = new Process();<br>
- process.StartInfo.FileName = exexutableFilename;
- </p></font><font face="Tahoma" size="1">
-
- <li>Calling the Start method on the component instance:
-
- </font><font face="Courier New" color="Blue" size="1"><p>
- process.Start();
- </p></font><font face="Tahoma" size="1">
-
- </ol>
-
- <p>A call to WaitForInputIdle will make sure the application actually starts and is
- ready to be used.</p>
-
- </font></div>
-
- <h4>Example</h4>
-
- <p>
- <div class="indent">
- <a target="_blank" href="/quickstart/howto/samples/Services/Process/ProcessDemo">
- <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br>
- </a>
- <div class="caption">ProcessDemo.exe</div><br>
- [<a target="_blank" href="/quickstart/howto/samples/Services/Process/ProcessDemo">View Sample</a>] |
- [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/Process/ProcessDemo/processdemo.src">View Source</a>]<p>
- </div>
-
- <h4>Source Code</h4>
-
- <div class="code">
- <xmp>
- <!-- #include virtual="/quickstart/howto/samples/Services/Process/ProcessDemo/ProcessDemo.cs" -->
- </xmp>
- </div>
-
- <!-- #include virtual="/quickstart/howto/include/footer.inc" -->