• <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 閱讀(311) 評論(0)  編輯 收藏 引用
            亚洲狠狠综合久久| 色8久久人人97超碰香蕉987| 久久精品国产亚洲沈樵| 99久久精品无码一区二区毛片| 日日狠狠久久偷偷色综合0 | 青青草国产精品久久| 91精品日韩人妻无码久久不卡| 亚洲国产综合久久天堂| 女人香蕉久久**毛片精品| 久久午夜免费视频| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 国产69精品久久久久777| 无码任你躁久久久久久久| 久久99热精品| 少妇内射兰兰久久| 久久综合亚洲色HEZYO国产| 久久99国产乱子伦精品免费| 欧美精品乱码99久久蜜桃| 久久精品成人免费看| 国内精品久久久久久久97牛牛| 国产精品成人久久久| 久久婷婷人人澡人人| 国产99久久久国产精品~~牛| 亚洲精品无码久久久久去q| 香蕉久久夜色精品国产2020| 久久99精品久久久久久不卡| AV无码久久久久不卡蜜桃| 久久久久免费看成人影片| 亚洲午夜久久久久久久久久| 久久综合鬼色88久久精品综合自在自线噜噜| 婷婷综合久久狠狠色99h| 久久国产一区二区| 日本一区精品久久久久影院| 青青草国产精品久久久久| 7国产欧美日韩综合天堂中文久久久久 | 国内精品久久久久影院一蜜桃| 色8久久人人97超碰香蕉987| 久久婷婷五月综合色奶水99啪| 久久成人国产精品免费软件| 五月丁香综合激情六月久久| 波多野结衣中文字幕久久|