用WMI可以实现实现远程启动或者关掉一个进程的功能
解决方案 »
- VS2005打开如下代码的.csproj代码报错“此安装不支持该项目类型”
- 求WMI的Win32_*字符串大全
- c#问题
- winform中的GridView列头如何添加控件?
- ClickOnce部署中發布Ini文件
- 正则表达式如何拆解字符串
- windows mobile收发邮件
- 怎样在C#中编程访问网上邻居
- 关于oracle--blob(clob)的操作问题,各位请进,分不够再加
- 求助做的是个网站,前台html,后台用C#写的,用json向前台传数据,如何进行分页,实现每次从后台读10个数据,在前台进行分页
- ▲▲▲▲▲ 主窗口 子窗口 之间的高级问题 ▲▲▲▲▲
- 请问怎样才能在DataGrid每行前面加上CheckBoxes?就像listView中设置了CheckBoxes一样
using System.Data;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Security;
using System.Security.Permissions;
namespace Z3
{
public class Processes
{ public static DataSet ps( string machineName )
{
Process[] psList = Process.GetProcesses(machineName); DataSet ds = new DataSet("processes");
ds.Tables.Add("ps");
DataColumn[] cols = {new DataColumn("PID", typeof(string)),
new DataColumn("Name", typeof(string)),
new DataColumn("Priority", typeof(string)),
new DataColumn("vmSize", typeof(string)),
new DataColumn("workingSetSize", typeof(string)),
new DataColumn("threadCount", typeof(string)),
new DataColumn("File", typeof(string)),
new DataColumn("handleCount", typeof(string))}; ds.Tables["ps"].Columns.AddRange(cols);
//table for process's modules
ds.Tables.Add("modules"); DataColumn[] modcols = {new DataColumn("PID", typeof(string)),
new DataColumn("CompanyName", typeof(string)),
new DataColumn("ModuleName", typeof(string)),
new DataColumn("FileName", typeof(string)),
new DataColumn("FileVersion", typeof(string)),
new DataColumn("IsPatched", typeof(string))}; ds.Tables["modules"].Columns.AddRange(modcols); //hold the values
object[] vals = new object[8];
object[] modvals = new object[6];
// Create a security permission object, needed for some reason on some machines
SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.AllFlags);
perm.Assert(); int psCount = psList.Length;
int modCount;
for( int i = 0; i < psCount; i++ )
{
try
{
// pid
vals[0] = psList[i].Id;
}
catch( Exception )
{
vals[0] = "n/a";
} try
{
// ProcessName
vals[1] = psList[i].ProcessName;
}
catch( Exception )
{
vals[1] = "n/a";
} try
{
// Priority
vals[2] = psList[i].PriorityClass;
}
catch( Exception )
{
vals[2] = "n/a";
} try
{
// VirtualMemorySize
vals[3] = psList[i].VirtualMemorySize;
}
catch( Exception )
{
vals[3] = "n/a";
} try
{
// WorkingSet
vals[4] = psList[i].WorkingSet;
}
catch( Exception )
{
vals[4] = "n/a";
} try
{
// ThreadCount
vals[5] = psList[i].Threads.Count;
}
catch( Exception )
{
vals[5] = "n/a";
} try
{
// HandleCount
vals[7] = psList[i].HandleCount;
}
catch( Exception )
{
vals[7] = "n/a";
}
try
{
// FileName (full path)
vals[6] = psList[i].MainModule.FileName;
}
catch( Exception )
{
vals[6] = "n/a";
} //insert a new row
ds.Tables["ps"].Rows.Add(vals);
try
{
//iterate thru modules for this process
modCount = psList[i].Modules.Count;
for( int z = 0; z < modCount; z++ )
{
modvals[0] = vals[0]; try
{
modvals[1] = psList[i].Modules[z].FileVersionInfo.CompanyName;
}
catch( Exception )
{
modvals[1] = "unknown";
}
try
{
modvals[2] = psList[i].Modules[z].ModuleName;
}
catch( Exception )
{
modvals[2] = "unknown";
}
try
{
modvals[3] = psList[i].Modules[z].FileName;
}
catch( Exception )
{
modvals[3] = "unknown";
}
try
{
modvals[4] = psList[i].Modules[z].FileVersionInfo.FileVersion;
}
catch( Exception )
{
modvals[4] = "unknown";
}
try
{
modvals[5] = psList[i].Modules[z].FileVersionInfo.IsPatched;
}
catch( Exception )
{
modvals[5] = "unknown";
} //insert a new row
ds.Tables["modules"].Rows.Add(modvals);
}
}
catch( Exception )
{
//nothing, this is for System and Idle processes, they don't have any modules
}
} // Create a relationship between tables
ds.Relations.Add("Process_Modules", ds.Tables["ps"].Columns["PID"], ds.Tables["modules"].Columns["PID"]); return ds;
} // IDispose
public void Dispose()
{
// Not holding any external resources.
} }
}
System.Management命名空间下的类。