Post: [C#] Get system process
12-11-2014, 04:38 AM #1
Teenage Modz
Do a barrel roll!
(adsbygoogle = window.adsbygoogle || []).push({}); Hello ngu, today i was messing around and i found this vb.net code to get system process. i took the liberty of converting it to C# so some people could understand it better so without further explination here it is

    static class Module1
{
public static void Main()
{
System.Diagnostics.Process p = default(System.Diagnostics.Process);
foreach (var p in System.Diagnostics.Process.GetProcesses) {
Console.WriteLine(p.ProcessName);
}
}
}
Last edited by Teenage Modz ; 12-11-2014 at 01:22 PM.
12-11-2014, 09:58 AM #2
Cyb3r
NextGenUpdate Elite
Originally posted by Another View Post
Hello ngu, today i was messing around and i found this vb.net code to get system process. i took the liberty of converting it to C# so some people could understand it better so without further explination here it is

static class Module1
{
public static void Main()
{
System.Diagnostics.Process p = default(System.Diagnostics.Process);
foreach (var p in System.Diagnostics.Process.GetProcesses) {
Console.WriteLine(p.ProcessName);
}
}
}


You could use this only:

    using System.Diagnostics;

foreach (Process p in Process.GetProcesses())
{
Console.WriteLine(p.ProcessName);
}


If you want specific process you can use GetProcessesByName:
    
foreach (Process p in Process.GetProcessesByName("notepad"))
{
Console.WriteLine(p.ProcessName);
}

If you want to check if it's running or not use this:

    
Process[] process = Process.GetProcessesByName("notepad");
if (process.Length > 0)
{
Console.WriteLine("Notepad is running");
}
else
{
Console.WriteLine("Notepad is not running");
}
Last edited by Cyb3r ; 12-11-2014 at 10:11 AM.

The following user thanked Cyb3r for this useful post:

Winter
12-11-2014, 01:17 PM #3
Winter
Purple God
You can actually do a lot with the Diagnostics class, It's worth looking into if you want to make PC RTE tools for different programs (or games) since you need to get process id's with it using the class (it's just one thing that came to mind), But next time you have something to share wrap it in
     instead of [ spoiler ] (it just makes it all the most neater, And as Cyb3r pointed out you can use it for detecting if a process is currently running or not :p & you can use it for killing processes also)

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo