using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
process1.Start();
}
private void button2_Click(object sender, EventArgs e)
{
FileInfo file = new FileInfo(@"C:\Windows\System32\calc.exe");
if (file.Exists)
{
Process proc = new Process();
proc.StartInfo.FileName = file.FullName;
proc.Start();
}
}
private void button3_Click(object sender, EventArgs e)
{
Process[] cp;
cp = Process.GetProcessesByName("calc");
//cp = Process.GetProcessesByName("calc.exe");
int i = cp.Length;
foreach (Process instance in cp)
{
instance.Close();
}
}
}
}
有两个启动计算器的按钮,一个关闭所有计算器进程的按钮,关闭的按钮获取不到计算器的进程为什么呢
#include /*数学函数的定义*/
#include /*屏幕操作函数*/
#include /*I/O函数*/
#include /*库函数*/
#include /*变量长度参数表*/
#include /*图形函数*/
#include /*字符串函数*/
#include /*字符操作函数*/
#define UP 0x48 /*光标上移键*/
#define DOWN 0x50 /*光标下移键*/
#define LEFT 0x4b /*光标左移键*/
#define RIGHT 0x4d /*光标右移键*/
#define ENTER 0x0d /*回车键*/
void rar; /全局变量,保存光标图象*/
struct palettetype palette; /*使用调色板信息*/
int GraphDriver; /* 图形设备驱动*/
int GraphMode; /* 图形模式值*/
int ErrorCode; /* 错误代码*/
int MaxColors; /* 可用颜色的最大数值*/
int MaxX, MaxY; /* 屏幕的最大分辨率*/
double AspectRatio; /* 屏幕的像素比*/
void drawboder(void); /*画边框函数*/
void initialize(void); /*初始化函数*/
void computer(void); /*计算器计算函数*/
void changetextstyle(int font, int direction, int charsize); /*改变文本样式函数*/
void mwindow(char header); /窗口函数*/
int specialkey(void) ; /*获取特殊键函数*/
int arrow(); /*设置箭头光标函数*/
/*主函数*/
int main()
{
instance.Kill();
计算器的进程contain(“calc”)??
Process[] p = Process.GetProcessesByName("calc");
for(int i=0;i<p.lenght;i++)
{
p[i].Kill();
}
Process[] ps = Process.GetProcessesByName("calc");
foreach (Process p in ps)
{
p.CloseMainWindow();
}
测试过可以关闭