Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取所有运行的.Net应用程序(不是Java)_C#_Hook - Fatal编程技术网

C# 获取所有运行的.Net应用程序(不是Java)

C# 获取所有运行的.Net应用程序(不是Java),c#,hook,C#,Hook,我在下面使用了这段代码,得到了在窗口中运行的所有应用程序 现在我只想得到.Net(.exe)的应用程序。你能帮我吗 public Form1() { InitializeComponent(); EnumWindows(new WindowEnumCallback(this.AddWnd), 0); } public delegate bool WindowEnumCallback(int hwnd, int lparam); [DllImport("user32.dll")

我在下面使用了这段代码,得到了在窗口中运行的所有应用程序

现在我只想得到.Net(.exe)的应用程序。你能帮我吗

public Form1()
{
    InitializeComponent();
    EnumWindows(new WindowEnumCallback(this.AddWnd), 0);
}

public delegate bool WindowEnumCallback(int hwnd, int lparam);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool EnumWindows(WindowEnumCallback lpEnumFunc, int lParam);

[DllImport("user32.dll")]
public static extern void GetWindowText(int h, StringBuilder s, int nMaxCount);

[DllImport("user32.dll")]
public static extern bool IsWindowVisible(int h);

private List<string> Windows = new List<string>();
private bool AddWnd(int hwnd, int lparam)
{
    if (IsWindowVisible(hwnd))
    {
        StringBuilder sb = new StringBuilder(255);
        GetWindowText(hwnd, sb, sb.Capacity);
        Windows.Add(sb.ToString());
        txtTest.Text += hwnd.ToString()+" ";
        lst.Items.Add(sb.ToString());
    }

    return true;
}
public Form1()
{
初始化组件();
EnumWindows(新的WindowEnumCallback(this.AddWnd),0);
}
公共委托bool WindowEnumCallback(int-hwnd,int-lparam);
[DllImport(“user32.dll”)]
[返回:Marshallas(UnmanagedType.Bool)]
静态外部布尔枚举窗口(WindowEnumCallback lpEnumFunc,int LPRAM);
[DllImport(“user32.dll”)]
公共静态外部无效GetWindowText(int h、StringBuilder s、int nMaxCount);
[DllImport(“user32.dll”)]
公共静态外部文件IsWindowVisible(inth);
私有列表窗口=新列表();
私有布尔地址(内部hwnd、内部lparam)
{
如果(IsWindowVisible(hwnd))
{
StringBuilder sb=新的StringBuilder(255);
GetWindowText(hwnd、sb、sb容量);
添加(sb.ToString());
txtTest.Text+=hwnd.ToString()+“”;
添加(sb.ToString());
}
返回true;
}

您可以使用如下方法,以及p/Invoke函数
GetFileVersion()


函数失败时不会引发异常。返回值不是0表示发生了错误,可执行文件不是.Net程序集。因此,上面的
IsDotNetExecutable
方法相应地返回
true
false

um,
.NET
!=
.exe
。您需要弄清楚应用程序是否使用.net framework的DLL,我不确定这是否很容易确定。。。也许是的,有人会给出答案,但是。。祝你好运“嗯,.NET!=.exe.”谢谢^^为什么不呢?你有错误吗?也许你不明白我的问题。^^。好的,现在当我构建这个应用程序,并且有更多的applicaton.net正在运行时,我会让所有的application.net都按应用程序运行。作为回答,.net应用程序必须具有路径。我认为它不起作用,因为我没有得到所有应用程序正在运行的路径。对不起我的英语。我的英语对我来说很差,也许我可以跟你说我的好话^^好吧,我明白你的意思。您并不总是或者永远都没有可执行文件的路径。请检查以了解如何从正在运行的进程获取路径。好的,谢谢!让我试试。哦,你知道“胡克”吗?我正在构建一个应用程序,当我的应用程序正在运行时,它将获取所有正在运行的应用程序.net,并获取应用程序.net中正在运行的所有控件(按钮、网格视图、表格、标签)。我知道我必须通过dll使用“钩子”,我必须将dll注入.net应用程序。但我不知道该从哪里开始?sr我的英语^^谢谢分享:)
[DllImport("mscoree.dll", CharSet = CharSet.Unicode)]
private static extern int GetFileVersion(string path, StringBuilder buffer, int buflen, out int written);

public static bool IsDotNetExecutable(string path)
{
    StringBuilder sBuilder = new StringBuilder(256);
    int written;
    int gvf = GetFileVersion(path, sBuilder, sBuilder.Capacity, out written);

    return gvf == 0;
}