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 开篇:为什么写这篇文章 先说下我自己的情况,我是个普通的大四学生,之前在 ...
随机推荐
- 解决MySQL中【Cannot load from mysql.proc. The table is probably corrupted
[错误过程]:MySQL从5.1升级至5.5后在调用存储过程时报出“Cannot load from mysql.proc. The table is probably corrupted.” [造成 ...
- 230. Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Not ...
- 2015GitWebRTC编译实录4
2015.07.17 libg711 编译通过[422/1600 ] CC obj /webrtc/modules/audio_coding/codecs/g711/g711.g711.o[423/1 ...
- this指针基础介绍
=================this指针的由来==================== 一个学生可以有多本书一样,而这些书都是属于这个同学的:同理,如果有很多个同学在一起,那么为了确定他们的书不 ...
- 4-1 yum源文件
1.Yum源文件 <1>在Linux中,有这样一个目录 /etc/yum.repos.d/,里面有默认4个yum源文件, 其中Base是基本yum源文件,它是默认生效的 其他的几个默认都是 ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- P168 实战练习(构造方法)
尝试编写一个矩形类,将长宽做为矩形类的属性,在构造方法中将长宽初始化,定义一个成员方法求此矩形的面积. 编写代码如下: 创建Rectangular类,则相关代码为: package org.hanqi ...
- 深入理解html5系列-文本标签
转:http://blog.csdn.net/lihui130135/article/details/45150501 文章简介: 关于html5相信大家早已经耳熟能详,但是他真正的意义在 ...
- struts2获得request和session对象
在struts1中,获得到系统的request或者session对象非常方便,都是按照形参传递的,但是在struts2中,request和session都被隐藏了 struts2提供两种方式访问ses ...
- android向web提交参数的4种方式总结,附带网站案例源码
第一种:基于http协议通过get方式提交参数 1.对多个参数的封装 public static String get_save(String name, String phone) { /** * ...