• <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)  編輯 收藏 引用
            亚洲午夜精品久久久久久人妖| 2019久久久高清456| 久久久久亚洲精品无码蜜桃| 国内精品久久久久久久97牛牛| 久久发布国产伦子伦精品| 久久久噜噜噜久久| 无码精品久久久久久人妻中字| 日韩精品久久久久久| 久久久午夜精品福利内容| AV色综合久久天堂AV色综合在| 欧美大战日韩91综合一区婷婷久久青草| 国内精品伊人久久久久777| 夜夜亚洲天天久久| 久久精品麻豆日日躁夜夜躁| 色综合合久久天天给综看| 国产综合久久久久| 一本一道久久综合狠狠老| 欧美色综合久久久久久| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 欧美激情精品久久久久| 久久精品国产99国产精品导航| 久久国产V一级毛多内射| 精品国产一区二区三区久久| 精品人妻伦九区久久AAA片69| 人人狠狠综合久久亚洲| 精品国产热久久久福利| 色综合久久综合网观看| 狠狠色婷婷综合天天久久丁香| 久久人人爽人人爽人人AV | 欧洲国产伦久久久久久久| 一本色道久久88加勒比—综合| 精品国际久久久久999波多野| 亚洲国产精品无码久久久蜜芽| 思思久久99热只有频精品66| 久久国产亚洲精品| 久久久久久午夜精品| 久久久久国产精品三级网| 久久天天躁狠狠躁夜夜2020| 久久久久人妻一区精品果冻| 久久99精品国产麻豆蜜芽| 欧美性猛交xxxx免费看久久久|