c#启动进程
//System.Diagnostics.Process p = new System.Diagnostics.Process();
//p.StartInfo.FileName = @"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe";
//p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动
//p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
//p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
//p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
//p.StartInfo.CreateNoWindow = true;//不显示程序窗口
//p.Start();//启动程 Process[] processes = Process.GetProcesses();
foreach (Process item in Process.GetProcesses())
{
if (item.ProcessName.Contains("WeChat"))
{
item.StartInfo.FileName = @"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe";
item.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动
item.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
item.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
item.StartInfo.RedirectStandardError = true;//重定向标准错误输出
item.StartInfo.CreateNoWindow = true;//不显示程序窗口
item.Start();//启动程序
}
}
启动
private void StartQueueExe()
{
string filePath = AppDomain.CurrentDomain.BaseDirectory;
FileInfo file = new FileInfo(filePath);
//filePath = file.Directory.Parent.Parent.FullName + "\\ZB.QueueSystem\\ZB.QueueSystem.exe";
filePath = file.Directory.FullName + "\\ZB.QueueSystem\\ZB.QueueSystem.exe"; System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = filePath;
p.StartInfo.UseShellExecute = false; //是否使用操作系统shell启动
p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
p.StartInfo.CreateNoWindow = true;//不显示程序窗口
p.Start();//启动程序
}
停止
private void KillProcessExists()
{
Process[] processes = Process.GetProcessesByName("AppStart");
foreach (Process p in processes)
{
if (System.IO.Path.Combine(Application.StartupPath, "AppStart.exe") == p.MainModule.FileName)
{
p.Kill();
p.Close();
}
}
} /// <summary>
/// 关闭进程
/// </summary>
/// <param name="processName">进程名</param>
private void KillProcess(string processName)
{
Process[] myproc = Process.GetProcesses();
foreach (Process item in myproc)
{
if (item.ProcessName == processName)
{
item.Kill();
}
}
}
查看是否存在指定进程:
private bool CheckProcessExists()
{
Process[] processes = Process.GetProcessesByName("test");
foreach (Process p in processes)
{
if (System.IO.Path.Combine(Application.StartupPath, "test.exe") == p.MainModule.FileName)
return true;
}
return false;
}
c#启动进程的更多相关文章
- Linux如何查看进程、杀死进程、启动进程等常用命令
Linux如何查看进程.杀死进程.启动进程等常用命令 关键字: linux 查进程.杀进程.起进程1.查进程 ps命令查找与进程相关的PID号: ps a 显示现行终端机下的所有程序,包括 ...
- C#单独启动进程的几种方式
本文实例讲述了C#启动进程的几种常用方法.分享给大家供大家参考.具体如下: 1.启动子进程,不等待子进程结束 private void simpleRun_Click(object sender, S ...
- C# 启动进程和杀死进程
/// <summary> /// 杀死进程 /// </summary> private void KillProcesses() { var cfn = GetAppset ...
- init启动进程
init启动进程需要读取()配置文件 1,启动init进程的配置文件是/etc/inittab 2,/etc/sysvinit是系统初始化用的 /sbin/init在核心完整的加载后,开始运行系统 ...
- c#根据文件路径启动进程
//根据文件路径启动进程 private static void StartProcessByFilePath(string path) { Process p = new System.Diagno ...
- Git Extensions system.invalidoperationexception尚未提供文件名,因此无法启动进程
根据别人的博客按照步骤安装,地址如下:http://www.cnblogs.com/sorex/archive/2011/08/10/2132359.html 但是安装Git Extensions后生 ...
- 【运维】linux命令查看端口占用情况,杀死进程,后台启动进程
1.查看端口占用情况:> lsof -i:port COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME ...
- 踩坑留印,启动进程遇到报错:/proc/self/fd/9: 2: ulimit: bad number
启动进程,遇到报错: /proc/self/fd/9: 2: ulimit: bad number 分析配置文件内容没有错误. 怀疑可能是文件格式问题,在IDE里面查看,果然是windows格式.ID ...
- java API Runtime 启动进程
Runtime run = new Runtime.getRuntime(); Process p = run.exec("notepad.exe F:\\lesson\\a.java&qu ...
- Android如何配置init.rc中的开机启动进程(service)【转】
本文转载自:http://blog.csdn.net/qq_28899635/article/details/56289063 开篇:为什么写这篇文章 先说下我自己的情况,我是个普通的大四学生,之前在 ...
随机推荐
- 利用range() 控制循环
s = ['a','b','c','d','e'] for i in range(len(s)):... if i < len(s)-1:... print s[i] a ...
- 自己写getElementsByClass()方法
// 根据类名获取元素 function getElementsByClass(oParent,sClass){ var aResult = []; var aNode = oParent.getEl ...
- 关于时间的util类,以后方便查阅
public static int lastDayOfMonth(int year, int month) { if (month == 2) { if (isLeapYear ...
- spark-scheduled调度算法
1.3源码是如此,后面新版本源码会尽可能的根据用户shell配置的参数进行分配 1.spareadOutApps 尽可能分配到多的机器上面execute和CPU core 2.非spareadouta ...
- glsl计算sprite的亮度饱和度对比度
//glsl计算sprite的亮度饱和度对比度 #ifdef GL_ES precision mediump float; #endif uniform sampler2D u_texture; va ...
- console下纯字符实现的俄罗斯方块
忙里偷闲,消遣一下,先上一张寒酸的效果图: 废话不多说,直接上代码,win7 64 code blocks编译通过. 吐槽一下cb的watch功能实在不够友好,不过免费的也不能要求太高. [按键说明] ...
- 论文笔记之:Fully-Convolutional Siamese Networks for Object Tracking
gansh Fully-Convolutional Siamese Network for Object Tracking 摘要:任意目标的跟踪问题通常是根据一个物体的外观来构建表观模型.虽然也取得了 ...
- MySQL删除重复记录只保留一条
删除表中重复记录,只保留一条: delete from 表名 where 字段ID in (select * from (select max(字段ID) from 表名 group by 重复的字段 ...
- 轮播图切换 纯html+js+css
如图所示. 该图片切换特效实现很简单,而且兼容性很好. html页面如下 复制代码代码如下: <div class="wrapper"> <div id=&quo ...
- Python元组的简单介绍
1.实际上元组是跟列表非常相近的另一种容器类型.元组和列表看上去的不同的一点是元组用圆括号而列表用方括号.而在功能上,元组是一种不可变的类型.正是因为这个原因,元组可以做一些列表不可以做的事情,比如用 ...