zoukankan      html  css  js  c++  java
  • c#启动EXE文件(简单的)

    在程序执行中会遇到启动本软件的exe问,或者启用其它的exe文件,已达到执行某些操作的作用。下面是两种最常见的启动exe文件。

    1、调用系统dll使用其提供的方法。

    引用的dll,

    [csharp] view plain copy
     
     print?
    1. [DllImport("kernel32.dll")]  
    2.   public static extern int WinExec(string exeName, int operType);  

    调用,WinExec(@"路径exe的文件名", 参数);

    operType参数如下:

    [csharp] view plain copy
     
     print?
    1. 0: 隐藏, 并且任务栏也没有最小化图标  
    2. 1: 用最近的大小和位置显示, 激活  
    3. 2: 最小化, 激活  
    4. 3: 最大化, 激活  
    5. 4: 用最近的大小和位置显示, 不激活  
    6. 5: 同 1  
    7. 6: 最小化, 不激活  
    8. 7: 同 3  
    9. 8: 同 3  
    10. 9: 同 1  
    11. 10: 同 1  

    2、最常见的ProcessStartInfo启动

    [csharp] view plain copy
     
     print?
    1. ProcessStartInfo info = new ProcessStartInfo();             
    2. info.FileName = @"路径exe的文件名";              
    3. info.Arguments = "";              
    4. info.WindowStyle = ProcessWindowStyle.Minimized;             
    5. Process pro = Process.Start(info);              
    6. pro.WaitForExit();  

    3、结束启动的exe的进程

    [csharp] view plain copy
     
     print?
    1. Process[] allProgresse = System.Diagnostics.Process.GetProcessesByName("exe的进程名");  
    2.  foreach (Process closeProgress in allProgresse)  
    3. {  
    4.    if (closeProgress.ProcessName.Equals("exe的进程名"))  
    5.          {  
    6.                 closeProgress.Kill();  
    7.                  closeProgress.WaitForExit();  
    8.                   break;  
    9.            }  
    10.  }  
  • 相关阅读:
    jQuery:一些小练习
    jQuery
    JavaWeb:笔记(三)
    JavaWeb:笔记(二)
    JavaWeb:笔记(一)
    JavaWeb:文件的上传下载
    JavaWeb:Listener
    基于RRT的机器人自主探索建图
    OpenNI2安装
    g2o初始化一些
  • 原文地址:https://www.cnblogs.com/TBW-Superhero/p/5570650.html
Copyright © 2011-2022 走看看