C# 强制关闭当前程序进程
来源:互联网 发布:windows7优化技巧 编辑:程序博客网 时间:2024/05/19 14:00
函数:
/// <summary>
/// 运行DOS命令
/// DOS关闭进程命令(ntsd -c q -p PID )PID为进程的ID
/// </summary>
/// <param name="command"></param>
/// <returns></returns>
public static string RunCmd(string command)
{
//实例一个Process类,启动一个独立进程
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe"; //设定程序名
p.StartInfo.Arguments = "/c " + command; //设定程式执行参数
p.StartInfo.UseShellExecute = false; //关闭Shell的使用
p.StartInfo.RedirectStandardInput = true; //重定向标准输入
p.StartInfo.RedirectStandardOutput = true; //重定向标准输出
p.StartInfo.RedirectStandardError = true; //重定向错误输出
p.StartInfo.CreateNoWindow = true; //设置不显示窗口
p.Start(); //启动
return p.StandardOutput.ReadToEnd(); //返回结果
}
==========================================================
在Program.cs加上如下:
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
//强制关闭进程
string exeName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
string[] exeArray = exeName.Split('\');
FunctionClass.RunCmd("taskkill /im " + exeArray[exeArray.Length-1] + " /f ");
}
}
转载http://jishu.hao513.com/html/software/csharp/20100622092849.html
- C# 强制关闭当前程序进程
- C# 强制关闭当前程序进程(完全Kill掉不留痕迹)
- c# 强制关闭进程
- C#强制关闭进程
- c#程序强制关闭所有进程方法(转载)
- C#中强制关闭某个进程
- C#强制关闭含QQ的所有进程,强制关闭最近打开的某个进程
- C#关闭当前excel进程方法
- C# 用程序强制杀死进程
- 强制关闭进程
- 强制关闭进程方法
- API HOOK 例子程序(HOOK资源管理器强制关闭进程)
- vbs强制关闭程序
- mac 强制关闭程序
- c# 关闭其他程序窗口/进程
- C# 关闭其他程序窗口、进程
- C# 关闭其他程序窗口、进程
- VC关闭当前进程
- C#中Split用法
- MFC中CALLBACK函数 和WINAPI函数的区别
- shell之“>/dev/null 2>&1”
- WPF 控件模板 Simple Styles.xaml
- addFieldToFilter 与 addAttributeToFilter使用总结
- C# 强制关闭当前程序进程
- 为何WP了不起,市场却争不过Android
- OpenGL源代码之基本框架
- 百度修改算法 增加对微博的索引
- VS2008建立C#工程时提示'{7D96DB16-7AF8-11DO-8E5E-00A0C911005A}'的QueryService失败
- SQL2005 怎么获取汉字的拼音首字母
- WinCE io口操作 流程 入门 请教
- WPF中找指定类型控件列表 (UIElementExtensions.cs)
- pageprivate的几处reference