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 开篇:为什么写这篇文章 先说下我自己的情况,我是个普通的大四学生,之前在 ...
随机推荐
- win10新增快捷键
按此键 出现位置 重要程度 联想记忆 替代 用途 +A 打开“操作中心” 右侧, ★★★★★ Action 控制面板 +S ...
- Linux1.0源代码编译过程
根据源代码包中的readme文件及http://chfj007.blog.163.com/blog/static/173145044201191195856806/?suggestedreading& ...
- Open经验库网址
http://www.open-open.com/lib/view/open1436094840774.html
- 基础套接字的C#网络编程
1.基于socket创建套接字网络连接服务端1.初始化 步骤 操作 方法 操作类 1. 创建ip ipaddress IPAddress类 2. 创建ip终结点 ipendpoint IpendP ...
- Linux驱动设计——阻塞和同步
阻塞和非阻塞是设备访问的两种基本方式,阻塞和非阻塞驱动程序使用时,经常会用到等待队列. 阻塞和非阻塞 阻塞操作是指在执行设备操作时,若不能获得资源,则挂起进程直到满足可操作的条件后再进行操作.被挂起的 ...
- 对于python,一切事物都是对象,对象基于类创建
新建列表.新建string字符串 li1 = [1, 2, 3, 4] li2 = list([1, 2, 3]) s1 = "abc" s2 = str("abc&qu ...
- Awesome Python
Awesome Python A curated list of awesome Python frameworks, libraries, software and resources. Insp ...
- 特征值分解与奇异值分解(SVD)
1.使用QR分解获取特征值和特征向量 将矩阵A进行QR分解,得到正规正交矩阵Q与上三角形矩阵R.由上可知Ak为相似矩阵,当k增加时,Ak收敛到上三角矩阵,特征值为对角项. 2.奇异值分解(SVD) 其 ...
- phpstorm编辑器智能提示框架代码
按照上面的步骤就可以智能提示代码了!
- 委托,C#本身的委托(Action Func)
1.Action 分为带泛型的和不带泛型的,带泛型可传入任何类型的参数. 格式如下: using System; using System.Collections.Generic; using Sys ...