麻烦懂的人 教下!
麻烦懂的人 教下!
呵呵 我刚做了一个控制台的,给你源码看看,有点简陋
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("程序设计:王伟");
}
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
listView1.FullRowSelect = true;
listView1.View = View.Details;
listView1.Columns.Clear();
listView1.Items.Clear();
ColumnHeader ColHeader;
Process[] Processes = Process.GetProcesses(); //获取所有的Process
//添加ListView控件的列头
ColHeader = new ColumnHeader();
ColHeader.Text = "ProcID";
ColHeader.TextAlign = HorizontalAlignment.Left ;
ColHeader.Width = 80;
listView1.Columns.Add(ColHeader);
ColHeader = new ColumnHeader();
ColHeader.Text = "ProcMainModule";
ColHeader.TextAlign = HorizontalAlignment.Right ;
ColHeader.Width = 200;
listView1.Columns.Add(ColHeader);
ColHeader = new ColumnHeader();
ColHeader.Text = "ProcessName";
ColHeader.TextAlign = HorizontalAlignment.Left;
ColHeader.Width = 150;
listView1.Columns.Add(ColHeader);
ListViewItem ListItem ;
try
{
foreach(Process proc in Processes) //遍历系统所有的Process
{
ListItem = new ListViewItem();
ListItem.Text = proc.Id.ToString();
ListItem.SubItems.Add(proc.MainModule.ModuleName.ToString());
ListItem.SubItems.Add(proc.ProcessName.ToString());
listView1.Items.Add(ListItem);
}
}
catch{}
}
哦 呵呵 很好用耶~~~
[此贴子已经被作者于2006-10-11 11:25:33编辑过]
你搞了這麼久c#.......