How do I determine if a Process is Managed in C#?

前端 未结 2 487
长发绾君心
长发绾君心 2020-12-11 18:46

A bit of searching returns this result: Which processes are running managed code and which version?

However I am wondering if there is a \'better\' way then simply i

相关标签:
2条回答
  • 2020-12-11 19:10

    For any future Googlers: I ended up using the suggested answer posted here How to check if a program is using .NET? (thanks 0xA3!)

    Process mProcess = //Get Your Process Here
    foreach (ProcessModule pm in mProcess.Modules)
    {
        if (pm.ModuleName.StartsWith("mscor", StringComparison.InvariantCultureIgnoreCase))
        {
            return true;
        }
    }
    

    As an aside looking for "mscorwks.dll" as mentioned in my original post does not work for .NET 4.0.

    0 讨论(0)
  • 2020-12-11 19:11

    In code, get the full path of the executing process. Try to use Assembly.Load on the process. If it works, it's a .Net assembly :)

    0 讨论(0)
提交回复
热议问题