C#如何运行外部程序(打开可执行程序):ShellExcute和Process
最近的任务用到C#来调用C++内核程序,也就是C++编译运行后生成的.exe文件。网搜了一下C#中运行外部程序大致有两种方法,在此稍作总结:
(1)使用API函数ShellExcute
添加引用 using System.Runtime.InteropServices;
public enum ShowWindowCommands : int
{
SW_HIDE = ,
SW_SHOWNORMAL = , //用最近的大小和位置显示,激活
SW_NORMAL = ,
SW_SHOWMINIMIZED = ,
SW_SHOWMAXIMIZED = ,
SW_MAXIMIZE = ,
SW_SHOWNOACTIVATE = ,
SW_SHOW = ,
SW_MINIMIZE = ,
SW_SHOWMINNOACTIVE = ,
SW_SHOWNA = ,
SW_RESTORE = ,
SW_SHOWDEFAULT = ,
SW_MAX =
}
[DllImport("shell32.dll")]
public static extern IntPtr ShellExecute(
IntPtr hwnd,
string lpszOp,
string lpszFile,
string lpszParams,
string lpszDir,
ShowWindowCommands FsShowCmd
); ---------------------
执行语句只有这句:
ShellExecute(IntPtr.Zero, "open", "testIO.exe", null, null, ShowWindowCommands.SW_SHOWNORMAL);
对于ShellExecute函数,http://baike.baidu.com/link?url=j6AhrfaS5YyMQ_8peNIdCsM0SWCjMoVDK_Lbzi5A4lz7VjNNCRsZU-bXrYFgfe6T_Rd1MKjQ9GelkuolNqNx1K
另外,ShellExecute还有一些特殊用法,如打开网页,打开邮件窗口等,详细内容看参看上面的链接。
(2)使用Process类
添加引用using System.Diagnostics;
Process process = new Process();
//process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = "testIO.exe";
//process.StartInfo.CreateNoWindow = true;
process.Start();
如此即可用C#打开testIO.exe文件。。。。。。
C#如何运行外部程序(打开可执行程序):ShellExcute和Process的更多相关文章
- delphi调用外部程序打开文件
delphi调用外部程序打开文件 ShellExecute的各种用法 一.利用系统默认的邮件收发器发送电子邮件 Uses ..., ShellAPI; Var lpHwnd: HWND; lpOper ...
- [转]Java中使用Runtime和Process类运行外部程序
帖子1: 使用Runtime.getRuntime().exec()方法可以在java程序里运行外部程序. 1. exec(String command) 2. exec(String comma ...
- 与众不同 windows phone (38) - 8.0 关联启动: 使用外部程序打开一个文件或URI, 关联指定的文件类型或协议
[源码下载] 与众不同 windows phone (38) - 8.0 关联启动: 使用外部程序打开一个文件或URI, 关联指定的文件类型或协议 作者:webabcd 介绍与众不同 windows ...
- 重新想象 Windows 8 Store Apps (33) - 关联启动: 使用外部程序打开一个文件或uri, 关联指定的文件类型或协议
原文:重新想象 Windows 8 Store Apps (33) - 关联启动: 使用外部程序打开一个文件或uri, 关联指定的文件类型或协议 [源码下载] 重新想象 Windows 8 Store ...
- 背水一战 Windows 10 (98) - 关联启动: 使用外部程序打开一个文件, 使用外部程序打开一个 Uri
[源码下载] 背水一战 Windows 10 (98) - 关联启动: 使用外部程序打开一个文件, 使用外部程序打开一个 Uri 作者:webabcd 介绍背水一战 Windows 10 之 关联启动 ...
- 【转载】Chrome使用自定义协议打开本地程序并运行IE打开网页
部分内容转载自: http://blog.sina.com.cn/s/blog_e2b8213a0102wqby.html 项目中遇到某需求:chorme要运行IE并打开网页.解决方案之一就是通过自定 ...
- C# ShellExcute与Process
C#运行外部程序的两种方法 ShellExecute using System.Runtime.InteropServices; public enum ShowWindowCommands : in ...
- C++中运行外部程序
关于三个SDK函数: WinExec, ShellExecute,CreateProcess 的其他注意事项: [1]定义头文件 必须定义以下两个头文件: #include <shlobj.h& ...
- c# 程序只能运行一次(多次运行只能打开同一个程序)
转自:https://social.msdn.microsoft.com/Forums/zh-CN/6398fb10-ecc2-4c03-ab25-d03544f5fcc9/2291420309357 ...
随机推荐
- Heroku 云服务部署流程
部署操作: heroic create bluefocus mkdir heroku && cd heroku --------------------- git init herok ...
- linux下如何编译安装gcc-8.3.0
1. 获取源码 wget https://mirrors.ustc.edu.cn/gnu/gcc/gcc-8.3.0/gcc-8.3.0.tar.xz -P ~ tar xvf gcc-8.3.0.t ...
- Mac OS X 显示和隐藏文件
参考: mac系统如何显示和隐藏文件 Mac OSX系统 显示和隐藏文件 1.显示隐藏文件: 打开Terminal,并输入以下命令: defaults write com.apple.finder A ...
- JavaScript闭包函数&箭头函数调用与执行
一.标准的闭包函数 //一.标准的闭包函数 function A() { var i=0; ++i; console.log('i : ' + i); return function b() { re ...
- ubuntu 18.04安装clojure工程的cli工具lein
官网的安装过程https://leiningen.org/#install 是文字描述,并不够lazy. 我仿照code,chrome nodejs的方式,给出下面的命令行安装过程 wget http ...
- html5画心
- systemctl用法及其语法
1.确定是否安装systemd及其版本 # systemctl –version 2.确定systemd和systemctl的二进制文件和库文件的安装位置 # whereis systemd # wh ...
- Quartz的时间配置
在公司要开发一个定时任务, 使用的quartz库, 其中的时间配置方式如下: 格式: [秒] [分] [小时] [日] [月] [周] [年] 序号 说明 是否必填 允许填写的值 允许的通配符 1 秒 ...
- 学生信息管理系统(C语言)
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct student ...
- gdb pretty printer for STL debug in Linux
Check your gcc version. If it is less than 4.7, you need use another printer.py file. Get the file f ...