麻烦懂的人 教下!
呵呵 我刚做了一个控制台的,给你源码看看,有点简陋
using System;
using System.Diagnostics;
struct process1
{
public string abc;
public process1(string abc)
{
this.abc=abc;
}
public void list()
{
Console.WriteLine("list all running process\n\n");
Process[] ps;
ps = Process.GetProcesses();
foreach( Process p in ps )
{
string pid=p.Id.ToString();
if(pid.Length==4)
{
Console.WriteLine("{0} {1}",pid,p.ProcessName.ToLower());
}
if(pid.Length==1)
{
Console.WriteLine("{0} {1}",pid,p.ProcessName.ToLower());
}
if(pid.Length==2)
{
Console.WriteLine("{0} {1}",pid,p.ProcessName.ToLower());
}
if(pid.Length==3)
{
Console.WriteLine("{0} {1}",pid,p.ProcessName.ToLower());
}
if(pid.Length>4)
{
Console.WriteLine("{0} {1}",pid,p.ProcessName.ToLower());
}
}
}
public void kill()
{
Console.WriteLine("{0}",abc);
try
{
Process[] process = Process.GetProcessesByName(abc);
foreach (Process kp in process)
{
kp.Kill();
}
}
catch( Exception e )
{
Console.WriteLine("{0}",e.Message);
}
}
}
class Class1
{
public static void Main(string[] args)
{
if(args.Length!=0)
{
if(args[0].Length!=0)
if(args[0]=="l" || args[0]=="L")
{
process1 aaaa=new process1();
aaaa.list();
}
else
{
string a=args[0];
process1 aaa=new process1();
aaa.abc=a;
aaa.kill();
}
}
if(args.Length==0)
{
Console.WriteLine("没有接收到任何参数\n");
Console.WriteLine("程序设计:王伟");
}
}
}