Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

c# - Check which version of DirectX is installed

As per the title, how can I check which version of DirectX a user has installed? Checking the FeatureLevel isn't enough, as my application can run on feature level 10.0, but requires that DirectX 11.1 be installed.

Why this is not a duplicate:

  • How to code to get direct X version on my machine in C#?
    • The first answer in this question says "If Windows 7, DirectX = 11, if Windows Vista, DirectX = 10". This is wrong, as Vista supports both DirectX 10 and 11 and Windows 7 supports DirectX 11 and 11.1.
    • The second answer references a registry key which only applies to DirectX 9 and lower. Even on a Windows 7 system with DirectX 11.1 installed, this registry key will never indicate an installed version greater than 9.0c
  • .NET How to detect if DirectX 10 is supported?
    • The answer to this question yet again references the same registry key for DirectX 9 and lower ONLY.

I need an answer that applies to DirectX 10 installs and up. That means determining if their version is 10, 10.1, 11 or 11.1.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

EDIT: Removed registry check method because it works only for Dx <=9 (thx @Telanor)

This method is very, very slow, but only one I figured out that is 100% accurate

private static int checkdxversion_dxdiag()
{
    Process.Start("dxdiag", "/x dxv.xml");
    while (!File.Exists("dxv.xml"))
        Thread.Sleep(1000);
    XmlDocument doc = new XmlDocument();
    doc.Load("dxv.xml");
    XmlNode dxd = doc.SelectSingleNode("//DxDiag");
    XmlNode dxv = dxd.SelectSingleNode("//DirectXVersion");

    return Convert.ToInt32(dxv.InnerText.Split(' ')[1]);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...