using Microsoft.Win32; using System; using System.Globalization; using System.Linq; using System.Runtime.InteropServices; using System.Windows.Forms; namespace Microsoft.WindowsUpdate.PrepareForWindowsTechnicalPreview { internal static class Program { public static bool DetermineLanguageEligibility() { bool flag; string[] strArray = new string[] { "en-us", "zn-cn", "pt-br", "en-gb", "ja-jp", "ru-ru", "de-de", "fr-fr", "ko-kr", "it-it", "es-es", "zh-tw", "sv-se", "fi-fi", "tr-tr", "ar-sa", "nl-nl", "cs-cz", "pl-pl", "th-th" }; flag = (!Enumerable.Contains(strArray, CultureInfo.get_CurrentCulture().ToString().ToLower()) ? false : true); return flag; } public static bool DetermineOSEligibility() { string str; bool servicePack; bool flag; RegistryKey registryKey = null; RegistryKey registryKey1 = null; try { registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"); if (null != registryKey) { string str1 = registryKey.GetValue("ProductName").ToString(); if (str1 == null) { flag = false; } else { flag = (str1.Contains("Windows 8.1") ? true : str1.Contains("Windows 7")); } if (!flag) { servicePack = false; } else if (str1.ToString().Contains("Windows 7")) { servicePack = Program.GetServicePack(); } else if (!str1.ToString().Contains("Windows 8.1")) { servicePack = false; } else { string environmentVariable = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE"); str = ((string.IsNullOrEmpty(environmentVariable) ? false : !("x86" == environmentVariable)) ? "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\Packages\\Package_for_KB2919355~31bf3856ad364e35~amd64~~6.3.1.14" : "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\Packages\\Package_for_KB2919355~31bf3856ad364e35~x86~~6.3.1.14"); registryKey1 = Registry.LocalMachine.OpenSubKey(str); servicePack = (null != registryKey1 ? "112" == registryKey1.GetValue("CurrentState").ToString() : false); } } else { servicePack = false; } } finally { if (null != registryKey) { registryKey.Close(); } if (null != registryKey1) { registryKey1.Close(); } } return servicePack; } public static bool GetServicePack() { bool flag; Program.OSVERSIONINFO oSVERSIONINFO = new Program.OSVERSIONINFO() { OSVersionInfoSize = Marshal.SizeOf(typeof(Program.OSVERSIONINFO)) }; Program.GetVersionEx(ref oSVERSIONINFO); flag = (!(string.Empty == oSVERSIONINFO.CSDVersion) ? true : false); return flag; } [DllImport("kernel32.Dll", CharSet=1, ExactSpelling=false)] public static extern short GetVersionEx(ref Program.OSVERSIONINFO o); [STAThread] private static void Main() { string str = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\WindowsTechnicalPreview"; string str1 = "Signup"; string str2 = "924EADEB-2472-490D-9203-5D0A1FD5CC73"; string str3 = "Prepare this PC"; string str4 = "We can't prepare this PC for Windows Technical Preview.\n\nMake sure it's using either Windows 7 SP1 or Windows 8.1 Update and a language supported in Windows Technical Preview."; string str5 = "This PC has already been prepared for Windows Technical Preview.\n\nWindows Update will let you know when the latest preview build is ready to install on this PC in early 2015."; string str6 = "Get your PC ready for the latest Windows Technical Preview build from Windows Update."; string str7 = "Your PC is now ready for Windows Technical Preview.\n\nWindows Update will let you know when the latest preview build is ready to install on this PC in early 2015."; string str8 = "We can't prepare this PC for Windows Technical Preview.\n\nHere's some info regarding the error:\n\n"; RegistryKey registryKey = null; RegistryKey registryKey1 = null; try { try { if ((!Program.DetermineOSEligibility() ? false : Program.DetermineLanguageEligibility())) { registryKey = Registry.LocalMachine.OpenSubKey(str, true); if (null != registryKey) { MessageBox.Show(str5, str3, 0); } else if (MessageBox.Show(str6, str3, 1) == 1) { registryKey1 = Registry.LocalMachine.CreateSubKey(str); registryKey1.SetValue(str1, str2); MessageBox.Show(str7, str3, 0); } } else { MessageBox.Show(str4, str3, 0); } } catch (Exception exception1) { Exception exception = exception1; MessageBox.Show(string.Concat(str8, exception.get_Message().ToString()), str3, 0); } } finally { if (null != registryKey) { registryKey.Close(); } if (null != registryKey1) { registryKey1.Close(); } } } public struct OSVERSIONINFO { public int OSVersionInfoSize; public int MajorVersion; public int MinorVersion; public int BuildNumber; public int PlatformId; public string CSDVersion; } } }