我想监视远程计算机上某些程式是否在执行。如不在执行,显示该程序名。
我已实现访问远程计算机并获得其正在执行的进程列表,怎么判断?
前题是:string ss = "QQ,OUTLOOK,explorer";不是QQ.exe。
发现:远程计算机进程列表中有写不是.exe后缀名,有些没有后缀名,求一个正则表达式读取字符串,从第一位读到点"."。static void Main(string[] args)
{
string ss = "QQ,OUTLOOK,explorer";
string[] program_list = ss.Split(',');
ConnectionOptions options = new ConnectionOptions();
options.Username = "administrator";//登陆远程计算机用户名称
options.Password = "password";//远程计算机用户密码
ManagementScope scope = new ManagementScope("\\\\" + "#.#.#.#" + "\\root\\cimv2", options);//#.#.#.#:远程IP
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process ");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get(); System.Data.DataTable result = new System.Data.DataTable();
result.Columns.Add("Name", Type.GetType("System.String"));
result.Columns.Add("ProcessId", Type.GetType("System.Int32"));
result.Columns.Add("Caption", Type.GetType("System.String"));
result.Columns.Add("Path", Type.GetType("System.String"));
foreach (ManagementObject m in queryCollection)
{
DataRow row = result.NewRow();
row["Name"] = m["Name"].ToString();
row["ProcessId"] = Convert.ToInt32(m["ProcessId"]);
if (m["Caption"] != null) row["Caption"] = m["Caption"].ToString();
if (m["ExecutablePath"] != null) row["Path"] = m["ExecutablePath"].ToString();
result.Rows.Add(row);
}
Console.Read();
}
我已实现访问远程计算机并获得其正在执行的进程列表,怎么判断?
前题是:string ss = "QQ,OUTLOOK,explorer";不是QQ.exe。
发现:远程计算机进程列表中有写不是.exe后缀名,有些没有后缀名,求一个正则表达式读取字符串,从第一位读到点"."。static void Main(string[] args)
{
string ss = "QQ,OUTLOOK,explorer";
string[] program_list = ss.Split(',');
ConnectionOptions options = new ConnectionOptions();
options.Username = "administrator";//登陆远程计算机用户名称
options.Password = "password";//远程计算机用户密码
ManagementScope scope = new ManagementScope("\\\\" + "#.#.#.#" + "\\root\\cimv2", options);//#.#.#.#:远程IP
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process ");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get(); System.Data.DataTable result = new System.Data.DataTable();
result.Columns.Add("Name", Type.GetType("System.String"));
result.Columns.Add("ProcessId", Type.GetType("System.Int32"));
result.Columns.Add("Caption", Type.GetType("System.String"));
result.Columns.Add("Path", Type.GetType("System.String"));
foreach (ManagementObject m in queryCollection)
{
DataRow row = result.NewRow();
row["Name"] = m["Name"].ToString();
row["ProcessId"] = Convert.ToInt32(m["ProcessId"]);
if (m["Caption"] != null) row["Caption"] = m["Caption"].ToString();
if (m["ExecutablePath"] != null) row["Path"] = m["ExecutablePath"].ToString();
result.Rows.Add(row);
}
Console.Read();
}
现在我已解决了。现在这分我给谁啊?伤脑筋
现在我已解决了。现在这分我给谁啊?伤脑筋
你们看,有2个1楼,神啊