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);
Developer technologies | C#
Developer technologies | 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.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Castorix31 91,406 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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.