• <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)  編輯 收藏 引用
            精品久久久久久无码人妻热| 久久中文娱乐网| 国产色综合久久无码有码| 亚洲成色www久久网站夜月| 久久精品国产99久久无毒不卡| 日韩精品国产自在久久现线拍| 久久男人AV资源网站| 久久久一本精品99久久精品66| 亚洲国产精品一区二区久久| 国内精品久久久久影院亚洲| 亚洲国产精品久久久久久| 亚洲综合久久夜AV | 亚洲国产精品久久久久婷婷老年 | 伊人久久大香线蕉综合网站| 久久99国产综合精品免费| 麻豆久久久9性大片| 国产精品一区二区久久精品| 久久人人青草97香蕉| 国产农村妇女毛片精品久久| 91精品国产综合久久精品| 久久偷看各类wc女厕嘘嘘| 中文字幕无码久久人妻| 久久婷婷五月综合97色直播| 国产成人无码精品久久久久免费| 久久久久久久亚洲Av无码| 久久精品人妻中文系列| 亚洲一级Av无码毛片久久精品| 亚洲一区中文字幕久久| 亚洲国产二区三区久久| 日本道色综合久久影院| 996久久国产精品线观看| 性欧美丰满熟妇XXXX性久久久| 久久午夜无码鲁丝片秋霞| 久久人人爽人人爽人人片av麻烦| 中文字幕精品久久久久人妻| 欧美精品丝袜久久久中文字幕| 久久影院亚洲一区| 久久人人爽人人爽人人片AV麻豆| 久久久无码精品亚洲日韩软件| 精品水蜜桃久久久久久久| 久久国产三级无码一区二区|