C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Trainings
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Show the Process and Application Names in C#
WhatsApp
Pritish Deshmukh
6y
55
k
0
2
25
Blog
getAllProcessID.zip
Show the Process Name also Application Name run in TaskManager in C# Consol
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Management;
using
System.Diagnostics;
using
System.Management.Instrumentation;
namespace
getAllProcessID
{
class
Program
{
static
void
Main(
string
[] args)
{
var myID = Process.GetCurrentProcess();
var query =
string
.Format(
"SELECT ParentProcessId FROM Win32_Process"
);
// WHERE ProcessId = {0}", myID);
var search =
new
ManagementObjectSearcher(
"root\\CIMV2"
, query);
var results = search.Get().GetEnumerator();
if
(!results.MoveNext())
throw
new
Exception(
"Huh?"
);
var queryObj = results.Current;
uint
parentId = (
uint
)queryObj[
"ParentProcessId"
];
// this code gives all process run in task manger
var parent = Process.GetProcesses();
//.GetProcessById((int)parentId);
foreach
(Process proc
in
parent)
{
Console.WriteLine(
"I was started by {0}"
, proc);
}
Console.ReadLine();
}
}
}
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Management;
using
System.Diagnostics;
using
System.Management.Instrumentation;
namespace
getAllProcessID
{
class
Program
{
static
void
Main(
string
[] args)
{
var myID = Process.GetCurrentProcess();
var query =
string
.Format(
"SELECT ParentProcessId FROM Win32_Process"
);
//WHERE ProcessId {0}", myID);
var search =
new
ManagementObjectSearcher(
"root\\CIMV2"
, query);
var results = search.Get().GetEnumerator();
if
(!results.MoveNext())
throw
new
Exception(
"Huh?"
);
var queryObj = results.Current;
uint
parentId = (
uint
)queryObj[
"ParentProcessId"
];
foreach
(Process p
in
Process.GetProcesses())
{
if
(p.MainWindowTitle.Length > 0)
{
Console.WriteLine(p.MainWindowTitle.ToString());
Console.WriteLine(p.ProcessName.ToString());
Console.WriteLine(p.MainWindowHandle.ToString());
Console.WriteLine(p.PrivateMemorySize64.ToString());
}
}
Console.ReadLine();
}
}
}
People also reading
Membership not found