How can I get Application name? in c#

harsha111111 121 Reputation points
2021-07-07T13:24:52.85+00:00

I used following code to get windows title but for application name p1 returns devenv instead of Visual Studio
If anyone knows how to resolve this issue, please let know

        var wnd = GetForegroundWindow();
        uint procId;
        GetWindowThreadProcessId(wnd, out procId);

        var p = Process.GetProcessById((int)procId).MainWindowTitle.ToString();
        var p1 = Process.GetProcessById((int)procId).ProcessName.ToString();


        string shortDateString = DateTime.Now.ToShortDateString();


        List<string> app = new List<string>();
        app.Add(p);
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,306 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,831 Reputation points
    2021-07-07T13:55:26.237+00:00

    For example :

    var p = Process.GetProcessById((int)procId).MainModule.FileName;
    FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(p);
    string sDescription = fvi.FileDescription;
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful