C#检测系统DirectX版本
C#检测DX版本代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
private int GetDirectxMajorVersion() { int directxMajorVersion = 0; var OSVersion = Environment.OSVersion; // if Windows Vista or later if (OSVersion.Version.Major >= 6) { // if Windows 7 or later if (OSVersion.Version.Major > 6 || OSVersion.Version.Minor >= 1) { directxMajorVersion = 11; } // if Windows Vista else { directxMajorVersion = 10; } } // if Windows XP or earlier. else { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\DirectX")) { string versionStr = key.GetValue("Version") as string; if (!string.IsNullOrEmpty(versionStr)) { var versionComponents = versionStr.Split('.'); if (versionComponents.Length > 1) { int directXLevel; if (int.TryParse(versionComponents[1], out directXLevel)) { directxMajorVersion = directXLevel; } } } } } return directxMajorVersion; } |
或者
1 2 3 4 5 6 7 8 9 10 11 12 |
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]); } |
如果您对C#游戏开发感兴趣,可以扫下面二维码加入我们的QQ群来一起学习交流
原创文章,转载请注明本文链接地址(违者必究):C#检测系统DirectX版本