[英]Windows 10: How to determine whether a process is an App/Background Process/Windows Process
Programmatically, how can I determine the 3 categories in Windows 10 以编程方式,我如何确定Windows 10中的3个类别
Just like Task Manager? 就像任务管理器一样?
ie I need some C# code which I can determine a list of Apps vs. a list of background process. 即我需要一些C#代码,可以确定应用程序列表还是后台进程列表。 Checking executionState in Win32_process doesn't work.
在Win32_process中检查executionState不起作用。 It's always null.
它始终为空。
Thanks! 谢谢!
The original problem: 原来的问题:
I have a different take regarding the solution: 对于解决方案,我有不同的看法:
Some UWP apps has the main window title. 某些UWP应用具有主窗口标题。 Checking main window title is not enough to say the app is running or not.
检查主窗口标题还不足以表明应用程序正在运行。
UWP apps in suspend state will still return the title (see the red rectangle) 处于挂起状态的UWP应用仍将返回标题(请参见红色矩形)
So in order to detect the suspend state, we need to cover 因此,为了检测暂停状态,我们需要
{code} {码}
static void byProcess()
{
Process[] processes = Process.GetProcesses();
List<string> suspendedAppsWhichHasTitle = new List<string>();
foreach (var proc in processes)
{
// if it has main window title
if (!string.IsNullOrEmpty(proc.MainWindowTitle))
{
// the app may be in suspend state
foreach (ProcessThread pT in proc.Threads)
{
ThreadState ts = pT.ThreadState;
if (ts == ThreadState.Running)
{
suspendedAppsWhichHasTitle.Add(proc.MainWindowTitle);
}
}
}
}
foreach(string app in suspendedAppsWhichHasTitle)
{
Console.WriteLine(app);
}
if (suspendedAppsWhichHasTitle.Count == 0)
{
Console.WriteLine("No visible app is running!");
}
Console.Read();
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.