• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            How can I run another application or batch file from my Visual C# .NET code?

            Published 01 June 04 11:54 PM

            Posted by: Duncan Mackenzie, MSDN
            This post applies to Visual C# .NET 2002/2003

            Suppose you want to run a command line application, open up another Windows program, or even bring up the default web browser or email program... how can you do this from your C# code?

            The answer for all of these examples is the same, you can use the classes and methods in System.Diagnostics.Process to accomplish these tasks and more.

            Example 1. Running a command line application, without concern for the results:

            private void simpleRun_Click(object sender, System.EventArgs e){
             System.Diagnostics.Process.Start(@"C:\listfiles.bat");
            }

            Example 2. Retrieving the results and waiting until the process stops (running the process synchronously):

            private void runSyncAndGetResults_Click(object sender, System.EventArgs e){
             System.Diagnostics.ProcessStartInfo psi =
              
            new System.Diagnostics.ProcessStartInfo(@"C:\listfiles.bat");
             psi.RedirectStandardOutput =
            true;
             psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
             psi.UseShellExecute =
            false;
             System.Diagnostics.Process listFiles;
             listFiles = System.Diagnostics.Process.Start(psi);
             System.IO.StreamReader myOutput = listFiles.StandardOutput;
             listFiles.WaitForExit(2000);
             
            if (listFiles.HasExited)
             {
              
            string output = myOutput.ReadToEnd();
              
            this.processResults.Text = output;
             }
            }

             Example 3. Displaying a URL using the default browser on the user's machine:

            private void launchURL_Click(object sender, System.EventArgs e){
             
            string targetURL = @http://www.duncanmackenzie.net;
             System.Diagnostics.Process.Start(targetURL);
            }

            In my opinion, you are much better off following the third example for URLs, as opposed to executing IE with the URL as an argument. The code shown for Example 3 will launch the user's default browser, which may or may not be IE; you are more likely to provide the user with the experience they want and you will be taking advantage of the browser that is most likely to have up-to-date connection information.

            C# code download available from http://www.duncanmackenzie.net/Samples/default.aspx

            By the way, this post is a simple port of an earlier VB FAQ post... just in case you thought you had seen it already in your feeds...

            Posted on 2009-11-17 13:10 micheal's tech 閱讀(305) 評論(0)  編輯 收藏 引用
            国产精品久久亚洲不卡动漫| 久久精品国产清自在天天线| 亚洲狠狠婷婷综合久久久久| 亚洲AV成人无码久久精品老人| 久久久久久九九99精品| 久久se精品一区精品二区| 精品欧美一区二区三区久久久| 国产一区二区精品久久岳| 一本色道久久综合狠狠躁篇| 久久久久久夜精品精品免费啦| 久久精品?ⅴ无码中文字幕| 色欲av伊人久久大香线蕉影院| 色狠狠久久综合网| 久久婷婷五月综合色高清| 日韩精品久久久久久| 一本一道久久a久久精品综合 | 办公室久久精品| 伊人久久精品无码av一区| 丁香五月综合久久激情| 一本色道久久88—综合亚洲精品 | 一本一道久久精品综合| 欧美熟妇另类久久久久久不卡| 久久精品国产亚洲Aⅴ蜜臀色欲| 伊人久久无码中文字幕| 久久久国产99久久国产一| 99久久精品免费看国产| 久久精品国产精品国产精品污| 色综合久久无码中文字幕| 中文精品99久久国产| 色婷婷狠狠久久综合五月| 精品久久久久国产免费| 国内精品久久久久久久影视麻豆| 国产精品久久午夜夜伦鲁鲁| 亚洲中文久久精品无码ww16| 久久久久人妻一区二区三区| 亚洲欧美国产日韩综合久久| 亚洲伊人久久成综合人影院| 亚洲欧美日韩久久精品| 久久久久精品国产亚洲AV无码| 欧美亚洲国产精品久久| 亚洲乱码中文字幕久久孕妇黑人|