How can I get Application name? in c#

harsha111111 121 Reputation points

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>();
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,190 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,446 Reputation points

    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