C#检测系统DirectX版本
C#检测DX版本代码如下:
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; }
或者
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]); }