c# 打开exe文件与关闭exe文件 c#服务打开exe时候默认是没有窗体界面的
2010-04-30 10:29
531 查看
原文地址:http://blog.csdn.net/2004v2004/archive/2009/03/21/4012650.aspx
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private static System.Diagnostics.Process LandEatSnake, LandFileDivisison;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)// 打开exe
{
try
{
if (LandFileDivisison == null)
{
LandFileDivisison = new System.Diagnostics.Process();
LandFileDivisison.StartInfo.FileName = "1.exe";
LandFileDivisison.Start();
}
else
{
if (LandFileDivisison.HasExited) //是否正在运行
{
LandFileDivisison.Start();
}
}
}
catch (Exception err)
{
MessageBox.Show("运行程序出错!" + err.ToString(), "出错信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button2_Click(object sender, EventArgs e) //关闭exe
{
Process[] pProcess;
pProcess = Process.GetProcesses();
for (int i = 1; i <= pProcess.Length - 1; i++)
{
if (pProcess[i].ProcessName == "1") //任务管理器 应用程序的名
{
pProcess[i].Kill();
break;
}
}
}
}
}
c#服务打开exe时候默认是没有窗体界面的
解决办法 是“点这个服务” “右键”--” 属性“ “登陆” 选择 “允许服务与桌面交互” 即可
try
{
if (LandFileDivisison == null)
{
LandFileDivisison = new System.Diagnostics.Process();
LandFileDivisison.StartInfo.FileName = strfilename;// "C://Temp//server.exe"; //换成你要执行的
LandFileDivisison.StartInfo.UseShellExecute = false;
LandFileDivisison.StartInfo.RedirectStandardInput = true;
LandFileDivisison.StartInfo.RedirectStandardOutput = true;
LandFileDivisison.StartInfo.RedirectStandardError = true;
LandFileDivisison.StartInfo.CreateNoWindow = true;
// LandFileDivisison.StartInfo.Arguments = "strdbname"; //传参数 打开exe
string strregvalue = strdbname +"," + struser + "," + strpassword + "," + strskyip + "," + strskyport;
WriteLog_text.WriteToLog("注册表数据 " + strregvalue + "/r/n");
LandFileDivisison.StartInfo.Arguments = strregvalue;
LandFileDivisison.Start();
WriteLog_text.WriteToLog("EXE" +"启动成功" + "/r/n");
}
else
{
if (LandFileDivisison.HasExited) //是否正在运行
{
LandFileDivisison.Start();
}
}
}
catch (Exception err)
{
WriteLog_text.WriteToLog("!" + err.ToString() + "启动成功" + "/r/n");
// MessageBox.Show("运行程序出错!" + err.ToString(), "出错信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/2004v2004/archive/2009/03/21/4012650.aspx
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private static System.Diagnostics.Process LandEatSnake, LandFileDivisison;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)// 打开exe
{
try
{
if (LandFileDivisison == null)
{
LandFileDivisison = new System.Diagnostics.Process();
LandFileDivisison.StartInfo.FileName = "1.exe";
LandFileDivisison.Start();
}
else
{
if (LandFileDivisison.HasExited) //是否正在运行
{
LandFileDivisison.Start();
}
}
}
catch (Exception err)
{
MessageBox.Show("运行程序出错!" + err.ToString(), "出错信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button2_Click(object sender, EventArgs e) //关闭exe
{
Process[] pProcess;
pProcess = Process.GetProcesses();
for (int i = 1; i <= pProcess.Length - 1; i++)
{
if (pProcess[i].ProcessName == "1") //任务管理器 应用程序的名
{
pProcess[i].Kill();
break;
}
}
}
}
}
c#服务打开exe时候默认是没有窗体界面的
解决办法 是“点这个服务” “右键”--” 属性“ “登陆” 选择 “允许服务与桌面交互” 即可
try
{
if (LandFileDivisison == null)
{
LandFileDivisison = new System.Diagnostics.Process();
LandFileDivisison.StartInfo.FileName = strfilename;// "C://Temp//server.exe"; //换成你要执行的
LandFileDivisison.StartInfo.UseShellExecute = false;
LandFileDivisison.StartInfo.RedirectStandardInput = true;
LandFileDivisison.StartInfo.RedirectStandardOutput = true;
LandFileDivisison.StartInfo.RedirectStandardError = true;
LandFileDivisison.StartInfo.CreateNoWindow = true;
// LandFileDivisison.StartInfo.Arguments = "strdbname"; //传参数 打开exe
string strregvalue = strdbname +"," + struser + "," + strpassword + "," + strskyip + "," + strskyport;
WriteLog_text.WriteToLog("注册表数据 " + strregvalue + "/r/n");
LandFileDivisison.StartInfo.Arguments = strregvalue;
LandFileDivisison.Start();
WriteLog_text.WriteToLog("EXE" +"启动成功" + "/r/n");
}
else
{
if (LandFileDivisison.HasExited) //是否正在运行
{
LandFileDivisison.Start();
}
}
}
catch (Exception err)
{
WriteLog_text.WriteToLog("!" + err.ToString() + "启动成功" + "/r/n");
// MessageBox.Show("运行程序出错!" + err.ToString(), "出错信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/2004v2004/archive/2009/03/21/4012650.aspx
相关文章推荐
- c# 打开exe文件与关闭exe文件 c#服务打开exe时候默认是没有窗体界面的
- 【SQLServer】【恢复挂起的解决方案】附加文件时候的提示“无法重新生成日志,原因是数据库关闭时存在打开的事务/用户,该数据库没有检查点或者该数据库是只读的。 ”【数据库恢复】
- C#中调用资源管理器(Explorer.exe)打开指定文件夹 + 并选中指定文件 + 调用(系统默认的播放类)软件(如WMP)打开(播放歌曲等)文件
- Ubuntu下安装android studio的时候,无法进入图形界面--/usr/lib/jdk1.8.0_60/jre/lib/i386/libawt_xawt.so: libXtst.so.6: 无法打开共享对象文件: 没有那个文件或目录
- C#中调用资源管理器(Explorer.exe)打开指定文件夹 + 并选中指定文件 + 调用(系统默认的播放类)软件(如WMP)打开(播放歌曲等)文件
- [转]C#中调用资源管理器(Explorer.exe)打开指定文件夹 + 并选中指定文件 + 调用(系统默认的播放类)软件(如WMP)打开(播放歌曲等)文件
- 【已解决】C#中调用资源管理器(Explorer.exe)打开指定文件夹 + 并选中指定文件 + 调用(系统默认的播放类)软件(如WMP)打开(播放歌曲等)文件
- 1、怎样设置C#OpenFileDialog(文件选择窗体)的指定路径、文件格式等属性(设置打开默认路径、文件格式、窗体显示文本)
- C# 获取网关地址 读取配置文件 打开关闭exe
- C# 自定义窗体上Icon图标和修改默认启动的exe文件的图标
- 在windows服务程序中打开带窗体的可执行文件
- C#中如何去除窗体默认的关闭按钮?[转自DIY部落]
- Windows 7 exe/桌面图标 文件打开方式关联错误,图标全部显示错误,打开方式关联了非系统默认打开方式 修复方案
- c#窗体关闭的时候关闭线程
- C# 关闭当前窗体打开另一窗体?
- C#中如何去除或屏蔽窗体默认的关闭按钮
- c#实现关闭当前窗体并打开另一个已经创建的窗体
- C# exe文件 添加到windows 服务
- 有时候当我们打开excel,没有看到常规的显示工作表界面,而是只显示了用户窗体。这是怎么实现的呢?
- unity .exe文件打开时跳过选择窗口界面的方式