How to Get Active Process Name in C#?

后端 未结 5 658
失恋的感觉
失恋的感觉 2020-12-01 06:43

How to get active process name in C#?

I know that I must use this code:

[DllImport(\"user32.dll\")]
private static extern IntPtr GetForegroundWindow(         


        
5条回答
  •  悲哀的现实
    2020-12-01 07:41

    I would suggest using System.Diagnostics.Process.

    var currentProc = System.Diagnostics.Process.GetCurrentProcess();
    string name = currentProc.ProcessName;
    

    As an alternative you could use:

    string name = currentProc.MainModule.FileName;
    

提交回复
热议问题