home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / QuickStart / howto / doc / processdemo.aspx < prev    next >
Encoding:
Text File  |  2000-06-08  |  2.7 KB  |  72 lines

  1.  
  2. <!-- #include virtual="/quickstart/howto/include/header.inc" -->
  3.  
  4. <h4>How Do I...Start and stop a process?</h4>
  5.  
  6. <div class="indent" style="width:660"><font face="Tahoma" size="1">
  7.  
  8. <p>You can use the Process component to accomplish
  9. most process management tasks quickly and easily. You can use this component to
  10. work with processes on either local or remote computers. On a local computer,
  11. you can for example start and stop a process.</p>
  12.  
  13. <p>This
  14. sample illustrates how to start and stop an executable. It's a small console application that can be run from a
  15. command prompt. The application takes one command line argument. The argument is
  16. a full path to the executable to be started. <b>Note</b>: this sample will only work on 
  17. processes which have a window and wait for input. Using this sample on a process which does not meet
  18. these criteria will cause an exception to be thrown.</p>
  19.  
  20. <p>For example, if you want to start and then stop Notepad, run
  21. the sample with the following command line argument:</p>
  22.  
  23.     </font><font face="Courier New" color="Blue" size="1"><blockquote>
  24.         > ProcessDemo.exe c:\winnt\notepad.exe
  25.     </blockquote></font><font face="Tahoma" size="1">
  26.  
  27. <p>You will see a notepad being started and then closed after approximately 1 second.</p>
  28.  
  29. <p>In its simplest form, starting a process involves:</p>
  30.  
  31. <ol>
  32. <li>Instantiating a Process component and initializing the path to an executable:
  33.  
  34.     </font><font face="Courier New" color="Blue" size="1"><p>
  35.         Process process = new Process();<br>
  36.         process.StartInfo.FileName = exexutableFilename;
  37.     </p></font><font face="Tahoma" size="1">
  38.  
  39. <li>Calling the Start method on the component instance:
  40.  
  41.     </font><font face="Courier New" color="Blue" size="1"><p>
  42.         process.Start();
  43.     </p></font><font face="Tahoma" size="1">
  44.  
  45. </ol>
  46.  
  47. <p>A call to WaitForInputIdle will make sure the application actually starts and is
  48. ready to be used.</p>
  49.  
  50. </font></div>
  51.  
  52. <h4>Example</h4>
  53.  
  54. <p>
  55. <div class="indent">
  56. <a target="_blank" href="/quickstart/howto/samples/Services/Process/ProcessDemo">
  57. <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br>
  58. </a>
  59. <div class="caption">ProcessDemo.exe</div><br>
  60. [<a target="_blank" href="/quickstart/howto/samples/Services/Process/ProcessDemo">View Sample</a>] | 
  61. [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/Process/ProcessDemo/processdemo.src">View Source</a>]<p>
  62. </div>
  63.  
  64. <h4>Source Code</h4>
  65.  
  66. <div class="code">
  67. <xmp>
  68. <!-- #include virtual="/quickstart/howto/samples/Services/Process/ProcessDemo/ProcessDemo.cs" -->
  69. </xmp>
  70. </div>
  71.  
  72. <!-- #include virtual="/quickstart/howto/include/footer.inc" -->