例如,如果我正在使用Visual Studio 2008,我想要值devenv和2008或9。

版本号非常重要......

有帮助吗?

解决方案

这将是PInvoke城市......

您需要PInvoke User32.dll中的以下API

Win32 :: GetForegroundWindow()返回当前活动窗口的HWND。

/// <summary>
/// The GetForegroundWindow function returns a handle to the foreground window.
/// </summary>
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();

Win32 :: GetWindowThreadProcessId(HWND,LPDWORD)返回给定HWND的PID

[DllImport("user32.dll", SetLastError=true)]
static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

在C#中

Process.GetProcessByID()获取PID以创建C#过程对象

processInstance.MainModule返回附加了FileVersionInfo的ProcessModule。

其他提示

项目演示了您需要的两个功能: EnumWindows GetWindowtext

你能澄清一下你的问题吗?你的意思是你想要一个程序运行,它会告诉你活动窗口中有关程序的数据吗?或者您希望程序报告自己的版本?

你想要获得的信息是 System.Reflection.Assembly 。 (请参阅链接中的代码示例。)

如何从外部程序获取程序集?那个我不确定...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top