# public static DataTable GetRunningProcesses()
# {
# //One way of constructing a query
# string wmiClass = "Win32_Process"
# string condition = ""
# string[] queryProperties = new string[] { "Name", "ProcessId", "Caption", "ExecutablePath", "CommandLine"乎蚂 }
# SelectQuery wmiQuery = new SelectQuery(wmiClass, condition, queryProperties)
# ManagementScope scope = new System.Management.ManagementScope(@"\\.\root\CIMV2")
#
# ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, wmiQuery)
# ManagementObjectCollection runningProcesses = searcher.Get()
#
# DataTable queryResults = new DataTable()
# queryResults.Columns.Add("Name", Type.GetType("System.String"))
# queryResults.Columns.Add("ProcessId", Type.GetType("System.Int32"))
# queryResults.Columns.Add("Caption", Type.GetType("System.String"))
# queryResults.Columns.Add("Path", Type.GetType("System.String"))
# queryResults.Columns.Add("CommandLine", Type.GetType("System.String"))
#
# foreach(ManagementObject obj in runningProcesses)
# {
# DataRow row = queryResults.NewRow()
# row["Name"] = obj["Name"].ToString()
# row["ProcessId"] = Convert.ToInt32(obj["ProcessId"])
# if (obj["Caption"]!= null)
# row["Caption"] = obj["Caption"].ToString()
# if (obj["ExecutablePath"]!= null)
# row["Path"] = obj["ExecutablePath"].ToString()
# if(obj["CommandLine"] != null)
# row["CommandLine"] = obj["CommandLine"].ToString()
# queryResults.Rows.Add( row )
# }
# return queryResults
# }
把cmd.exe 替换成bat文件核备握名,"/c dir" 替换成文件名后面的滚歼参数
供参改庆考:
System.Diagnostics.Process p = new System.Diagnostics.Process()
p.StartInfo=new System.Diagnostics.ProcessStartInfo("cmd.exe")
p.StartInfo.Arguments = "/c dir"
p.StartInfo.RedirectStandardOutput = true
p.StartInfo.UseShellExecute = false
p.Start()
p.WaitForExit()
string output=p.StandardOutput.ReadToEnd()
MessageBox.Show(output)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)