As the title implies, is there any way I could do this?
I'm trying to do this in an .aspx, this is my current code:
<script runat="server">
//using System.Diagnostics;
Process[] processes = Syst开发者_开发问答em.Diagnostics.Process.GetProcesses();
foreach(Process process in processes)
{
lbl = process.MainWindowTitle;
}
</script>
But it's saying foreach isn't a valid token.
Like everyone else said Process.GetProcesses()
If you use LinqPad you can run this in Statements mode to see how it works and play with it.
Process[] processes = Process.GetProcesses();
foreach(Process process in processes)
{
Console.WriteLine(process.ProcessName);
}
If you are using .NET, you can call System.Diagnostics.Process.GetProcesses()
to retrieve an array of Process
objects.
Note that this methods has overloads, and that perhaps one of the overloads may be more suitable to your situation.
精彩评论