简体   繁体   English

Windows 10:如何确定进程是否为应用程序/背景进程/ Windows进程

[英]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个类别

  • Apps 应用
  • Background process 后台流程
  • Windows service Windows服务

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: 原来的问题:

  • How to detect list of running apps? 如何检测正在运行的应用程序列表?

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 因此,为了检测暂停状态,我们需要

  1. app has title but not running in the foreground 应用具有标题,但未在前台运行
  2. app has title but not running in the background 应用具有标题,但未在后台运行

{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.

相关问题 如何获取进程“类型”(应用程序,后台进程或Windows进程) - How to get process “type” (App, Background Process, or Windows Process) Windows窗体会在应用程序退出时终止后台进程 - Windows forms kill background process on app exit .NET如何检查Windows进程是否正在作为“应用程序”或“背景应用程序”运行 - .NET How to check if a Windows process is running as an “App” or as a “Background application” 无法在Windows 10周年更新中启动带有进程的Windows App - Unable to launch Windows App with Process in Windows 10 Anniversary Update 如何使Windows形成后台进程? - How to make windows form a background process? 在锁定的 Windows 10 机器上的后台进程中将文本放入剪贴板 - Put text to clipboard in the background process on locked Windows 10 machine 处理Windows应用程序的最终过程 - Handling end process of a windows app 在后台进程中获取Windows Store App的设备宽高比 - Get Device Aspect Ratio for Windows Store App in Background Process 如何在C#中确定Windows进程使用的tcp端口 - How to determine tcp port used by Windows process in C# 如何从ServiceController确定Windows.Diagnostics.Process - How to determine Windows.Diagnostics.Process from ServiceController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM