• <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久久99久久精品国产片果冻| 日韩精品国产自在久久现线拍| 99久久免费国产精品| 中文精品久久久久人妻| 少妇精品久久久一区二区三区 | 一本久道久久综合狠狠躁AV| 久久精品无码一区二区WWW| 久久国产高潮流白浆免费观看| 国产精品青草久久久久福利99| 亚洲精品无码久久毛片| 东方aⅴ免费观看久久av| 99久久国产综合精品网成人影院| 亚洲v国产v天堂a无码久久| 成人免费网站久久久| 中文字幕精品久久| 国产精品成人久久久久三级午夜电影| 久久综合亚洲色HEZYO国产| 一级做a爱片久久毛片| 欧美亚洲国产精品久久| 亚洲国产天堂久久综合| 伊人久久大香线焦综合四虎| 午夜天堂av天堂久久久| 久久亚洲精品成人无码网站| 狠狠久久综合伊人不卡| 国产韩国精品一区二区三区久久| 狠狠色噜噜色狠狠狠综合久久| 亚洲欧美日韩精品久久亚洲区| 精品无码久久久久久久久久| 久久精品人人做人人爽电影| 久久免费视频观看| 浪潮AV色综合久久天堂| 亚洲va国产va天堂va久久| 国产精品亚洲综合久久| 亚洲乱码日产精品a级毛片久久| 久久精品国产第一区二区| 久久久久九九精品影院| 色悠久久久久久久综合网| 婷婷久久五月天| 无码超乳爆乳中文字幕久久|