diff --git a/.vs/CMWTAT_DIGITAL/v15/.suo b/.vs/CMWTAT_DIGITAL/v15/.suo index 136c275..3b036cf 100644 Binary files a/.vs/CMWTAT_DIGITAL/v15/.suo and b/.vs/CMWTAT_DIGITAL/v15/.suo differ diff --git a/.vs/CMWTAT_DIGITAL/v15/Server/sqlite3/storage.ide b/.vs/CMWTAT_DIGITAL/v15/Server/sqlite3/storage.ide index e89fb90..ef602ed 100644 Binary files a/.vs/CMWTAT_DIGITAL/v15/Server/sqlite3/storage.ide and b/.vs/CMWTAT_DIGITAL/v15/Server/sqlite3/storage.ide differ diff --git a/.vs/CMWTAT_DIGITAL/v15/Server/sqlite3/storage.ide-shm b/.vs/CMWTAT_DIGITAL/v15/Server/sqlite3/storage.ide-shm new file mode 100644 index 0000000..383db34 Binary files /dev/null and b/.vs/CMWTAT_DIGITAL/v15/Server/sqlite3/storage.ide-shm differ diff --git a/.vs/CMWTAT_DIGITAL/v15/Server/sqlite3/storage.ide-wal b/.vs/CMWTAT_DIGITAL/v15/Server/sqlite3/storage.ide-wal new file mode 100644 index 0000000..c87abf1 Binary files /dev/null and b/.vs/CMWTAT_DIGITAL/v15/Server/sqlite3/storage.ide-wal differ diff --git a/CMWTAT_DIGITAL/CMWTAT.ico b/CMWTAT_DIGITAL/CMWTAT.ico deleted file mode 100644 index 42f687a..0000000 Binary files a/CMWTAT_DIGITAL/CMWTAT.ico and /dev/null differ diff --git a/CMWTAT_DIGITAL/CMWTAT.png b/CMWTAT_DIGITAL/CMWTAT.png deleted file mode 100644 index e0ebb76..0000000 Binary files a/CMWTAT_DIGITAL/CMWTAT.png and /dev/null differ diff --git a/CMWTAT_DIGITAL/CMWTAT_DIGITAL.csproj b/CMWTAT_DIGITAL/CMWTAT_DIGITAL.csproj index 949fbb2..134b446 100644 --- a/CMWTAT_DIGITAL/CMWTAT_DIGITAL.csproj +++ b/CMWTAT_DIGITAL/CMWTAT_DIGITAL.csproj @@ -82,6 +82,9 @@ App.xaml Code + + + MainWindow.xaml Code diff --git a/CMWTAT_DIGITAL/Domain/IsSN.cs b/CMWTAT_DIGITAL/Domain/IsSN.cs new file mode 100644 index 0000000..3e5bbfe --- /dev/null +++ b/CMWTAT_DIGITAL/Domain/IsSN.cs @@ -0,0 +1,82 @@ +using System; +using System.Globalization; +using System.Text.RegularExpressions; +using System.Windows.Controls; + +namespace CMWTAT_DIGITAL.Domain +{ + class IsSN : ValidationRule + { + #region 匹配方法 + + /// + /// 验证字符串是否匹配正则表达式描述的规则 + /// + /// 待验证的字符串 + /// 正则表达式字符串 + /// 是否匹配 + public static bool IsMatch(string inputStr, string patternStr) + { + return IsMatch(inputStr, patternStr, false, false); + } + + /// + /// 验证字符串是否匹配正则表达式描述的规则 + /// + /// 待验证的字符串 + /// 正则表达式字符串 + /// 匹配时是否不区分大小写 + /// 是否匹配 + public static bool IsMatch(string inputStr, string patternStr, bool ifIgnoreCase) + { + return IsMatch(inputStr, patternStr, ifIgnoreCase, false); + } + + /// + /// 验证字符串是否匹配正则表达式描述的规则 + /// + /// 待验证的字符串 + /// 正则表达式字符串 + /// 匹配时是否不区分大小写 + /// 是否验证空白字符串 + /// 是否匹配 + public static bool IsMatch(string inputStr, string patternStr, bool ifIgnoreCase, bool ifValidateWhiteSpace) + { + if (!ifValidateWhiteSpace && string.IsNullOrEmpty(inputStr)) + return false;//如果不要求验证空白字符串而此时传入的待验证字符串为空白字符串,则不匹配 + Regex regex = null; + if (ifIgnoreCase) + regex = new Regex(patternStr, RegexOptions.IgnoreCase);//指定不区分大小写的匹配 + else + regex = new Regex(patternStr); + return regex.IsMatch(inputStr); + } + + #endregion + + public override ValidationResult Validate(object value, CultureInfo cultureInfo) + { + //Console.WriteLine("\""+value+"\""); + //return string.IsNullOrWhiteSpace((value ?? "").ToString()) + // ? new ValidationResult(false, "Key is required.") + // : ValidationResult.ValidResult; + + string pattern = @"^[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}$"; + + if (IsMatch((value ?? "").ToString(), pattern)) + { + return ValidationResult.ValidResult; + + } + else if (string.IsNullOrWhiteSpace((value ?? "").ToString())) + { + return new ValidationResult(false, "Please enter the key for the current edition."); + } + else + { + return new ValidationResult(false, "Invalid format."); + } + + } + } +} diff --git a/CMWTAT_DIGITAL/Domain/NotifyPropertyChangedExtension.cs b/CMWTAT_DIGITAL/Domain/NotifyPropertyChangedExtension.cs new file mode 100644 index 0000000..4d9a982 --- /dev/null +++ b/CMWTAT_DIGITAL/Domain/NotifyPropertyChangedExtension.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace CMWTAT_DIGITAL.Domain +{ + public static class NotifyPropertyChangedExtension + { + public static void MutateVerbose(this INotifyPropertyChanged instance, ref TField field, TField newValue, Action raise, [CallerMemberName] string propertyName = null) + { + if (EqualityComparer.Default.Equals(field, newValue)) return; + field = newValue; + raise?.Invoke(new PropertyChangedEventArgs(propertyName)); + } + } +} diff --git a/CMWTAT_DIGITAL/Domain/ViewModel.cs b/CMWTAT_DIGITAL/Domain/ViewModel.cs new file mode 100644 index 0000000..68d3228 --- /dev/null +++ b/CMWTAT_DIGITAL/Domain/ViewModel.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CMWTAT_DIGITAL.Domain +{ + class ViewModel : INotifyPropertyChanged + { + private string _sn; + + public ViewModel() + { + LongListToTestComboVirtualization = new List(Enumerable.Range(0, 1000)); + } + + public string SN + { + get { return _sn; } + set + { + this.MutateVerbose(ref _sn, value, RaisePropertyChanged()); + } + } + + public IList LongListToTestComboVirtualization { get; } + + public event PropertyChangedEventHandler PropertyChanged; + + private Action RaisePropertyChanged() + { + return args => PropertyChanged?.Invoke(this, args); + } + } +} diff --git a/CMWTAT_DIGITAL/MainWindow.xaml b/CMWTAT_DIGITAL/MainWindow.xaml index de4af81..1b71d6a 100644 --- a/CMWTAT_DIGITAL/MainWindow.xaml +++ b/CMWTAT_DIGITAL/MainWindow.xaml @@ -3,9 +3,10 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:domain="clr-namespace:CMWTAT_DIGITAL.Domain" xmlns:local="clr-namespace:CMWTAT_DIGITAL" mc:Ignorable="d" - Title="CMWTAT Digital Edition V2" Height="380" Width="450" + Title="CMWTAT Digital Edition V2" Height="550" Width="450" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" TextElement.Foreground="{DynamicResource MaterialDesignBody}" TextElement.FontWeight="Regular" @@ -13,148 +14,173 @@ TextOptions.TextFormattingMode="Ideal" TextOptions.TextRenderingMode="Auto" Background="{DynamicResource MaterialDesignPaper}" - FontFamily="{DynamicResource MaterialDesignFont}" ResizeMode="NoResize"> + FontFamily="{DynamicResource MaterialDesignFont}" + ResizeMode="NoResize" + d:DataContext="{d:DesignInstance domain:ViewModel, d:IsDesignTimeCreatable=False}" + > - + - - - - - - - - - - - - - Title - Hello World - - - + - - - - - - - - - - - - - Error - Unable to connect to server, program will exit. - - - + - - - - - - - - - - - - - Title - Text - - - + - - - - - - - - - - - - - Title - Congratulation! Windows 10 has been successful activated. - - - - + - - - - - + + + + + diff --git a/CMWTAT_DIGITAL/MainWindow.xaml.cs b/CMWTAT_DIGITAL/MainWindow.xaml.cs index ab049b0..f19ea8c 100644 --- a/CMWTAT_DIGITAL/MainWindow.xaml.cs +++ b/CMWTAT_DIGITAL/MainWindow.xaml.cs @@ -19,6 +19,8 @@ using System.Net; using System.IO; using System.Threading; using Microsoft.Win32; +using CMWTAT_DIGITAL.Domain; +using System.Text.RegularExpressions; namespace CMWTAT_DIGITAL { @@ -38,7 +40,13 @@ namespace CMWTAT_DIGITAL public string SystemEdition = OSVersionInfo.Edition; public MainWindow() { + InitializeComponent(); + + DataContext = new ViewModel(); + + this.DialogHostGrid.Visibility = Visibility.Visible; + //MessageBox.Show(@"reg add ""HKLM\SYSTEM\Tokens\"" /v ""Channel"" /t REG_SZ /d ""Retail"" /f"); DialogWait.IsOpen = true; try @@ -59,6 +67,9 @@ namespace CMWTAT_DIGITAL JArray ositems; int now_os_index = 0; string checked_os = "unknow"; + + bool is_auto = true; //是否为自动模式,false为手动 + private void InvokeTest() { actbtn.Dispatcher.Invoke(new Action(() => @@ -74,7 +85,7 @@ namespace CMWTAT_DIGITAL })); try { - string json = GetHttpWebRequest("https://kms.kumo.moe/api/digital?list=1"); + string json = GetHttpWebRequest("https://kms.kumo.moe/api/digital?list=1&ver=2"); JObject jsonobj = JObject.Parse(json); List list = new List(); Frequency freq = new Frequency(); @@ -93,6 +104,11 @@ namespace CMWTAT_DIGITAL now_os_index = i; checked_os = SystemEdition + OSVersionInfo.BuildVersion; } + if (jsonobj["OS"][i].ToString() == "(Experimental) " + SystemEdition) + { + now_os_index = i; + checked_os = "(Experimental) " + SystemEdition; + } list.Add(freq); } @@ -114,7 +130,6 @@ namespace CMWTAT_DIGITAL })); //this.SystemEditionText.SelectedIndex = now_os_index; - // 在此点之下插入创建对象所需的代码。 } catch { @@ -129,7 +144,7 @@ namespace CMWTAT_DIGITAL })); } - private void Button_Click(object sender, RoutedEventArgs e) + private void Activate_Button_Click(object sender, RoutedEventArgs e) { Thread actthread = new Thread(RunAct); actthread.Start(); @@ -141,6 +156,13 @@ namespace CMWTAT_DIGITAL //MessageBox.Show(rss["OS"][0].ToString()); //MessageBox.Show(SystemEdition); } + + private void installbtn_Click(object sender, RoutedEventArgs e) + { + Thread installthread = new Thread(RunInstall); + installthread.Start(); + } + private string GetHttpWebRequest(string url) { Uri uri = new Uri(url); @@ -164,6 +186,131 @@ namespace CMWTAT_DIGITAL Application.Current.Shutdown(); } + private void RunInstall() + { + actbtn.Dispatcher.Invoke(new Action(() => + { + this.DialogActProg.IsOpen = true; + this.activatingtext.Text = "Converting"; + })); + + Wow64EnableWow64FsRedirection(false);//关闭文件重定向 + + string code = "-0"; + string key = "00000-00000-00000-00000-00000"; + string sku = "0"; + string msg = "Unknow Error!"; + string system = ""; + + string slmgr = Environment.GetFolderPath(Environment.SpecialFolder.SystemX86) + "\\slmgr.vbs"; + string slmgr_self = System.AppDomain.CurrentDomain.BaseDirectory + "slmgr.vbs"; + + string changepk = Environment.SystemDirectory + "\\changepk.exe"; + + if (is_auto == true) + { + actbtn.Dispatcher.Invoke(new Action(() => + { + system = this.SystemEditionText.Text; + })); + + actbtn.Dispatcher.Invoke(new Action(() => + { + this.activatingtext.Text = "Getting Key"; + })); + + //获取密钥和SKU + try + { + + string json = GetHttpWebRequest("https://kms.kumo.moe/api/digital?list=0&ver=2"); + JObject jsonobj = JObject.Parse(json); + List list = new List(); + ositems = (JArray)jsonobj["OS"]; + key = jsonobj[system]["key"].ToString(); + sku = jsonobj[system]["sku"].ToString(); + Console.WriteLine("Edition:" + system + "\r\nKEY:" + key + "\r\nSKU:" + sku); + + } + catch + { + code = "-0"; + msg = "激活Windows10需要网络获取产品密钥 :) \nActivate Windows 10 requires a network to gets the product key :)"; + goto EndLine; + } + } + else + { + + //手动密钥 + + actbtn.Dispatcher.Invoke(new Action(() => + { + key = this.SystemEditionTextInput.Text; + })); + + } + + + actbtn.Dispatcher.Invoke(new Action(() => + { + this.activatingtext.Text = "Uninstalling old Key"; + })); + //卸载 + string runend = RunCScript(slmgr_self, "-upk").Trim(); + Console.WriteLine(runend); + if (runend.EndsWith("successfully.") || runend.EndsWith("not found.")) + { + + actbtn.Dispatcher.Invoke(new Action(() => + { + this.activatingtext.Text = "Installing Key"; + })); + + //安装数字权利升级密钥 + if (RunCScript(slmgr_self, "-ipk " + key).Trim().EndsWith("successfully.")) + { + code = "200"; + } + else + { + code = "-2"; + msg = "无法安装密钥,可能没有选择或输入正确的版本 :(\nCannot to install key, may be you choose or enter a incorrect version. :("; + } + } + else + { + code = "-1"; + msg = "无法卸载旧密钥 :(\nCannot to uninstall old key. :("; + } + //string runend = RunCScript(slmgr_self, "-upk").Trim(); + EndLine:; + if (code != "200") + { + actbtn.Dispatcher.Invoke(new Action(() => + { + this.DialogActProg.IsOpen = false; + this.activatingtext.Text = "Converting"; + this.DialogWithOKToCloseDialog.IsOpen = true; + this.DialogWithOKToCloseDialogTitle.Text = "Error"; + this.DialogWithOKToCloseDialogText.Text = msg + "\r\nCode:" + code; + })); + //MessageBox.Show(msg + "\r\nCode:" + code); + } + else + { + actbtn.Dispatcher.Invoke(new Action(() => + { + this.DialogActProg.IsOpen = false; + this.activatingtext.Text = "Converting"; + this.DialogWithOKToCloseDialogDonate.IsOpen = true; + this.DialogWithOKToCloseDialogDonateTitle.Text = "Complete"; + this.DialogWithOKToCloseDialogDonateText.Text = "\nCongratulation! \n\nWindows 10 has been successful converted.\n"; + })); + //MessageBox.Show("Congratulation!"); + } + } + private void RunAct() { actbtn.Dispatcher.Invoke(new Action(() => @@ -179,45 +326,68 @@ namespace CMWTAT_DIGITAL string sku = "0"; string msg = "Unknow Error!"; string system = ""; - actbtn.Dispatcher.Invoke(new Action(() => - { - system = this.SystemEditionText.Text; - })); - + string mode = "1"; //1:普通(SYS、SKU、KEY完全);2.需要获取SKU(SYS、KEY);3.手动输入KEY string slmgr = Environment.GetFolderPath(Environment.SpecialFolder.SystemX86) + "\\slmgr.vbs"; string slmgr_self = System.AppDomain.CurrentDomain.BaseDirectory + "slmgr.vbs"; string changepk = Environment.SystemDirectory + "\\changepk.exe"; - actbtn.Dispatcher.Invoke(new Action(() => - { - this.activatingtext.Text = "Getting Key"; - })); - - //获取密钥和SKU - try + if (is_auto == true) { - string json = GetHttpWebRequest("https://kms.kumo.moe/api/digital?list=0"); - JObject jsonobj = JObject.Parse(json); - List list = new List(); - ositems = (JArray)jsonobj["OS"]; - key = jsonobj[system]["key"].ToString(); - sku = jsonobj[system]["sku"].ToString(); - Console.WriteLine("Edition:" + system + "\r\nSKU:" + key + "\r\nSKU:" + sku); + actbtn.Dispatcher.Invoke(new Action(() => + { + system = this.SystemEditionText.Text; + })); + + actbtn.Dispatcher.Invoke(new Action(() => + { + this.activatingtext.Text = "Getting Key"; + })); + + //获取密钥和SKU + try + { + + string json = GetHttpWebRequest("https://kms.kumo.moe/api/digital?list=0&ver=2"); + JObject jsonobj = JObject.Parse(json); + List list = new List(); + ositems = (JArray)jsonobj["OS"]; + key = jsonobj[system]["key"].ToString(); + sku = jsonobj[system]["sku"].ToString(); + Console.WriteLine("Edition:" + system + "\r\nKEY:" + key + "\r\nSKU:" + sku); + + if (sku == "unknow") + { + mode = "2"; + } + + } + catch + { + code = "-0"; + msg = "激活Windows10需要网络获取产品密钥 :) \nActivate Windows 10 requires a network to gets the product key :)"; + goto EndLine; + } } - catch + else { - code = "-0"; - msg = "激活Windows10需要网络获取产品密钥 :) \nActivate Windows 10 requires a network to gets the product key :)"; - goto EndLine; + + actbtn.Dispatcher.Invoke(new Action(() => + { + key = this.SystemEditionTextInput.Text; + })); + mode = "3"; + } + actbtn.Dispatcher.Invoke(new Action(() => { this.activatingtext.Text = "Uninstalling old Key"; })); + //卸载 string runend = RunCScript(slmgr_self, "-upk").Trim(); Console.WriteLine(runend); @@ -226,6 +396,54 @@ namespace CMWTAT_DIGITAL RunCScript(slmgr_self, "-ckms").Trim(); + if (mode == "2" || mode == "3") + { + + actbtn.Dispatcher.Invoke(new Action(() => + { + this.activatingtext.Text = "Getting edition code (Experimental)"; + })); + + //安装转换密钥 + runend = RunCScript(slmgr_self, "-ipk " + key); + Console.WriteLine(slmgr_self + " -ipk " + key); + Console.WriteLine(runend); + if (runend.Trim().EndsWith("successfully.")) + { + Thread.Sleep(6000); //等待6秒,确保SKU生效 + sku = GetSKU(); //获取SKU + if (sku != "Error") + { + actbtn.Dispatcher.Invoke(new Action(() => + { + this.activatingtext.Text = "Uninstalling old Key (Experimental)"; + })); + + runend = RunCScript(slmgr_self, "-upk").Trim(); + Console.WriteLine(runend); + if (runend.EndsWith("successfully.") || runend.EndsWith("not found.")) + { + actbtn.Dispatcher.Invoke(new Action(() => + { + this.activatingtext.Text = "Prepare for the next step (Experimental)"; + })); + } + } + else + { + code = "-1.2"; + msg = "无法获取版本代号 :(\nCannot to get edition code. :("; + goto EndLine; + } + } + else + { + code = "-1.1"; + msg = "无法安装密钥,可能没有选择或输入正确的版本 :(\nCannot to install key, may be you choose or enter a incorrect version. :("; + goto EndLine; + } + } + //写入Win7特征 //ChangePKAction(changepk + " /ProductKey " + key); @@ -245,7 +463,10 @@ namespace CMWTAT_DIGITAL })); //安装数字权利升级密钥 - if (RunCScript(slmgr_self, "-ipk " + key).Trim().EndsWith("successfully.")) + runend = RunCScript(slmgr_self, "-ipk " + key); + Console.WriteLine(slmgr_self + " -ipk " + key); + Console.WriteLine(runend); + if (runend.Trim().EndsWith("successfully.")) { actbtn.Dispatcher.Invoke(new Action(() => @@ -298,13 +519,13 @@ namespace CMWTAT_DIGITAL else { code = "-3"; - msg = "执行超时,可能没有选择正确的版本 :(\nTime out, may be you choose a incorrect version. :("; + msg = "执行超时,可能没有选择正确或输入的版本 :(\nTime out, may be you choose or enter a incorrect version. :("; } } else { code = "-2"; - msg = "无法安装密钥,可能没有选择正确的版本 :(\nCannot to install key, may be you choose a incorrect version. :("; + msg = "无法安装密钥,可能没有选择或输入正确的版本 :(\nCannot to install key, may be you choose or enter a incorrect version. :("; } } else @@ -333,8 +554,8 @@ namespace CMWTAT_DIGITAL this.DialogActProg.IsOpen = false; this.activatingtext.Text = "Activating"; this.DialogWithOKToCloseDialogDonate.IsOpen = true; - //this.DialogWithOKToCloseDialogDonateTitle.Text = "Complete"; - //this.DialogWithOKToCloseDialogDonateText.Text = "Congratulation!"; + this.DialogWithOKToCloseDialogDonateTitle.Text = "Complete"; + this.DialogWithOKToCloseDialogDonateText.Text = "\nCongratulation! \n\nWindows 10 has been successful activated.\n"; })); //MessageBox.Show("Congratulation!"); } @@ -352,7 +573,7 @@ namespace CMWTAT_DIGITAL p.StartInfo.CreateNoWindow = true;//不显示程序窗口 p.Start();//启动程序 //向CMD窗口发送输入信息: - p.StandardInput.WriteLine(var); //10秒后重启(C#中可不好做哦) + p.StandardInput.WriteLine(var); Console.WriteLine(var); //Wow64EnableWow64FsRedirection(false);//关闭文件重定向 //System.Diagnostics.Process.Start(var); @@ -386,10 +607,71 @@ namespace CMWTAT_DIGITAL } } + public static string GetSKU() + { + Wow64EnableWow64FsRedirection(false);//关闭文件重定向 + //执行命令行函数 + try + { + System.Diagnostics.Process p = new System.Diagnostics.Process(); + p.StartInfo.FileName = "cmd.exe";//要执行的程序名称 + p.StartInfo.UseShellExecute = false; + p.StartInfo.RedirectStandardOutput = true; + p.StartInfo.CreateNoWindow = true; + p.StartInfo.Arguments = "/c wmic os get OperatingSystemSKU"; + //myProcessStartInfo.Arguments = "/c chcp 65001 > nul && cmd /c \"" + PHPRuntimePath + "\" \"" + path + "\" " + var; + //myProcessStartInfo.Arguments = "/c " & Commands + p.StartInfo.StandardOutputEncoding = Encoding.UTF8; + p.Start(); + p.WaitForExit(120 * 1000); + System.IO.StreamReader myStreamReader = p.StandardOutput; + string myString = myStreamReader.ReadToEnd(); + p.Close(); + myString = Regex.Replace(myString, @"[^0-9]+", ""); + Console.WriteLine("Get SKU:\"" + myString + "\""); + return myString; //只保留数字SKU + } + catch + { + return "Error"; + } + } + private void Donate_Button_Click(object sender, RoutedEventArgs e) { System.Diagnostics.Process.Start("https://waxel.cloudmoe.com/donate/"); this.DialogWithOKToCloseDialogDonate.IsOpen = false; } + + string last_key = ""; + + private void SystemEditionTextInput_TextChanged(object sender, TextChangedEventArgs e) + { + if (SystemEditionTextInput.Text != last_key) + { + int selectlen = SystemEditionTextInput.SelectionStart; + string temp = SystemEditionTextInput.Text; + temp = Regex.Replace(temp, @"[^a-zA-Z0-9]+", "");//XAML禁用输入法,并替换可能粘贴进的意外字符 + temp = Regex.Replace(temp, @"([a-zA-Z0-9]{5}(?!$))", "$1-"); + //temp = string.Join("-", Regex.Matches(temp, @".....").Cast().ToList()); + SystemEditionTextInput.Text = temp.ToUpper(); + last_key = SystemEditionTextInput.Text; + SystemEditionTextInput.SelectionStart = SystemEditionTextInput.Text.Length; + } + } + + private void A_RadioButton_Checked(object sender, RoutedEventArgs e) + { + SystemEditionText.Visibility = Visibility.Visible; + SystemEditionTextInput.Visibility = Visibility.Hidden; + is_auto = true; + } + + private void M_RadioButton_Checked(object sender, RoutedEventArgs e) + { + SystemEditionText.Visibility = Visibility.Hidden; + SystemEditionTextInput.Visibility = Visibility.Visible; + is_auto = false; + } } } diff --git a/CMWTAT_DIGITAL/Properties/AssemblyInfo.cs b/CMWTAT_DIGITAL/Properties/AssemblyInfo.cs index c82a4a5..84c3213 100644 --- a/CMWTAT_DIGITAL/Properties/AssemblyInfo.cs +++ b/CMWTAT_DIGITAL/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ using System.Windows; // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 // 方法是按如下所示使用“*”: : // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.0.0")] -[assembly: AssemblyFileVersion("2.0.0.0")] +[assembly: AssemblyVersion("2.1.0.0")] +[assembly: AssemblyFileVersion("2.1.0.0")] diff --git a/CMWTAT_Digital_Release_2_1_0_0.exe b/CMWTAT_Digital_Release_2_1_0_0.exe new file mode 100644 index 0000000..c322967 Binary files /dev/null and b/CMWTAT_Digital_Release_2_1_0_0.exe differ diff --git a/OSVersionInfoDLL/OSVersionInfoClass.cs b/OSVersionInfoDLL/OSVersionInfoClass.cs new file mode 100644 index 0000000..92aa648 --- /dev/null +++ b/OSVersionInfoDLL/OSVersionInfoClass.cs @@ -0,0 +1,1089 @@ +using Microsoft.Win32; +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; + +// http://www.codeproject.com/Articles/73000/Getting-Operating-System-Version-Info-Even-for-Win +//https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions + +//Thanks to Member 7861383, Scott Vickery for the Windows 8.1 update and workaround. +//I have moved it to the beginning of the Name property, though... + +//Thakts to Brisingr Aerowing for help with the Windows 10 adapatation + +namespace JCS +{ + /// + /// Provides detailed information about the host operating system. + /// + public static class OSVersionInfo + { + #region ENUMS + public enum SoftwareArchitecture + { + Unknown = 0, + Bit32 = 1, + Bit64 = 2 + } + + public enum ProcessorArchitecture + { + Unknown = 0, + Bit32 = 1, + Bit64 = 2, + Itanium64 = 3 + } + #endregion ENUMS + + #region DELEGATE DECLARATION + private delegate bool IsWow64ProcessDelegate([In] IntPtr handle, [Out] out bool isWow64Process); + #endregion DELEGATE DECLARATION + + #region BITS + /// + /// Determines if the current application is 32 or 64-bit. + /// + static public SoftwareArchitecture ProgramBits + { + get + { + SoftwareArchitecture pbits = SoftwareArchitecture.Unknown; + + System.Collections.IDictionary test = Environment.GetEnvironmentVariables(); + + switch (IntPtr.Size * 8) + { + case 64: + pbits = SoftwareArchitecture.Bit64; + break; + + case 32: + pbits = SoftwareArchitecture.Bit32; + break; + + default: + pbits = SoftwareArchitecture.Unknown; + break; + } + + return pbits; + } + } + + static public SoftwareArchitecture OSBits + { + get + { + SoftwareArchitecture osbits = SoftwareArchitecture.Unknown; + + switch (IntPtr.Size * 8) + { + case 64: + osbits = SoftwareArchitecture.Bit64; + break; + + case 32: + if (Is32BitProcessOn64BitProcessor()) + osbits = SoftwareArchitecture.Bit64; + else + osbits = SoftwareArchitecture.Bit32; + break; + + default: + osbits = SoftwareArchitecture.Unknown; + break; + } + + return osbits; + } + } + + /// + /// Determines if the current processor is 32 or 64-bit. + /// + static public ProcessorArchitecture ProcessorBits + { + get + { + ProcessorArchitecture pbits = ProcessorArchitecture.Unknown; + + try + { + SYSTEM_INFO l_System_Info = new SYSTEM_INFO(); + GetNativeSystemInfo(ref l_System_Info); + + switch (l_System_Info.uProcessorInfo.wProcessorArchitecture) + { + case 9: // PROCESSOR_ARCHITECTURE_AMD64 + pbits = ProcessorArchitecture.Bit64; + break; + case 6: // PROCESSOR_ARCHITECTURE_IA64 + pbits = ProcessorArchitecture.Itanium64; + break; + case 0: // PROCESSOR_ARCHITECTURE_INTEL + pbits = ProcessorArchitecture.Bit32; + break; + default: // PROCESSOR_ARCHITECTURE_UNKNOWN + pbits = ProcessorArchitecture.Unknown; + break; + } + } + catch + { + // Ignore + } + + return pbits; + } + } + #endregion BITS + + #region EDITION + static private string s_Edition; + /// + /// Gets the edition of the operating system running on this computer. + /// + static public string Edition + { + get + { + if (s_Edition != null) + return s_Edition; //***** RETURN *****// + + string edition = String.Empty; + + OperatingSystem osVersion = Environment.OSVersion; + OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX(); + osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX)); + + if (GetVersionEx(ref osVersionInfo)) + { + int majorVersion = osVersion.Version.Major; + int minorVersion = osVersion.Version.Minor; + byte productType = osVersionInfo.wProductType; + short suiteMask = osVersionInfo.wSuiteMask; + + #region VERSION 4 + if (majorVersion == 4) + { + if (productType == VER_NT_WORKSTATION) + { + // Windows NT 4.0 Workstation + edition = "Workstation"; + } + else if (productType == VER_NT_SERVER) + { + if ((suiteMask & VER_SUITE_ENTERPRISE) != 0) + { + // Windows NT 4.0 Server Enterprise + edition = "Enterprise Server"; + } + else + { + // Windows NT 4.0 Server + edition = "Standard Server"; + } + } + } + #endregion VERSION 4 + + #region VERSION 5 + else if (majorVersion == 5) + { + if (productType == VER_NT_WORKSTATION) + { + if ((suiteMask & VER_SUITE_PERSONAL) != 0) + { + edition = "Home"; + } + else + { + if (GetSystemMetrics(86) == 0) // 86 == SM_TABLETPC + edition = "Professional"; + else + edition = "Tablet Edition"; + } + } + else if (productType == VER_NT_SERVER) + { + if (minorVersion == 0) + { + if ((suiteMask & VER_SUITE_DATACENTER) != 0) + { + // Windows 2000 Datacenter Server + edition = "Datacenter Server"; + } + else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0) + { + // Windows 2000 Advanced Server + edition = "Advanced Server"; + } + else + { + // Windows 2000 Server + edition = "Server"; + } + } + else + { + if ((suiteMask & VER_SUITE_DATACENTER) != 0) + { + // Windows Server 2003 Datacenter Edition + edition = "Datacenter"; + } + else if ((suiteMask & VER_SUITE_ENTERPRISE) != 0) + { + // Windows Server 2003 Enterprise Edition + edition = "Enterprise"; + } + else if ((suiteMask & VER_SUITE_BLADE) != 0) + { + // Windows Server 2003 Web Edition + edition = "Web Edition"; + } + else + { + // Windows Server 2003 Standard Edition + edition = "Standard"; + } + } + } + } + #endregion VERSION 5 + + #region VERSION 6 + else if (majorVersion == 6) + { + int ed; + if (GetProductInfo(majorVersion, minorVersion, + osVersionInfo.wServicePackMajor, osVersionInfo.wServicePackMinor, + out ed)) + { + switch (ed) + { + case PRODUCT_BUSINESS: + edition = "Business"; + break; + case PRODUCT_BUSINESS_N: + edition = "Business N"; + break; + case PRODUCT_CLUSTER_SERVER: + edition = "HPC Edition"; + break; + case PRODUCT_CLUSTER_SERVER_V: + edition = "HPC Edition without Hyper-V"; + break; + case PRODUCT_DATACENTER_SERVER: + edition = "Datacenter Server"; + break; + case PRODUCT_DATACENTER_SERVER_CORE: + edition = "Datacenter Server (core installation)"; + break; + case PRODUCT_DATACENTER_SERVER_V: + edition = "Datacenter Server without Hyper-V"; + break; + case PRODUCT_DATACENTER_SERVER_CORE_V: + edition = "Datacenter Server without Hyper-V (core installation)"; + break; + case PRODUCT_EMBEDDED: + edition = "Embedded"; + break; + case PRODUCT_ENTERPRISE: + edition = "Enterprise"; + break; + case PRODUCT_ENTERPRISE_N: + edition = "Enterprise N"; + break; + case PRODUCT_ENTERPRISE_E: + edition = "Enterprise E"; + break; + case PRODUCT_ENTERPRISE_SERVER: + edition = "Enterprise Server"; + break; + case PRODUCT_ENTERPRISE_SERVER_CORE: + edition = "Enterprise Server (core installation)"; + break; + case PRODUCT_ENTERPRISE_SERVER_CORE_V: + edition = "Enterprise Server without Hyper-V (core installation)"; + break; + case PRODUCT_ENTERPRISE_SERVER_IA64: + edition = "Enterprise Server for Itanium-based Systems"; + break; + case PRODUCT_ENTERPRISE_SERVER_V: + edition = "Enterprise Server without Hyper-V"; + break; + case PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT: + edition = "Essential Business Server MGMT"; + break; + case PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL: + edition = "Essential Business Server ADDL"; + break; + case PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC: + edition = "Essential Business Server MGMTSVC"; + break; + case PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC: + edition = "Essential Business Server ADDLSVC"; + break; + case PRODUCT_HOME_BASIC: + edition = "Home Basic"; + break; + case PRODUCT_HOME_BASIC_N: + edition = "Home Basic N"; + break; + case PRODUCT_HOME_BASIC_E: + edition = "Home Basic E"; + break; + case PRODUCT_HOME_PREMIUM: + edition = "Home Premium"; + break; + case PRODUCT_HOME_PREMIUM_N: + edition = "Home Premium N"; + break; + case PRODUCT_HOME_PREMIUM_E: + edition = "Home Premium E"; + break; + case PRODUCT_HOME_PREMIUM_SERVER: + edition = "Home Premium Server"; + break; + case PRODUCT_HYPERV: + edition = "Microsoft Hyper-V Server"; + break; + case PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT: + edition = "Windows Essential Business Management Server"; + break; + case PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING: + edition = "Windows Essential Business Messaging Server"; + break; + case PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY: + edition = "Windows Essential Business Security Server"; + break; + case PRODUCT_PROFESSIONAL: + edition = "Professional"; + break; + case PRODUCT_PROFESSIONAL_N: + edition = "Professional N"; + break; + case PRODUCT_PROFESSIONAL_E: + edition = "Professional E"; + break; + case PRODUCT_SB_SOLUTION_SERVER: + edition = "SB Solution Server"; + break; + case PRODUCT_SB_SOLUTION_SERVER_EM: + edition = "SB Solution Server EM"; + break; + case PRODUCT_SERVER_FOR_SB_SOLUTIONS: + edition = "Server for SB Solutions"; + break; + case PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM: + edition = "Server for SB Solutions EM"; + break; + case PRODUCT_SERVER_FOR_SMALLBUSINESS: + edition = "Windows Essential Server Solutions"; + break; + case PRODUCT_SERVER_FOR_SMALLBUSINESS_V: + edition = "Windows Essential Server Solutions without Hyper-V"; + break; + case PRODUCT_SERVER_FOUNDATION: + edition = "Server Foundation"; + break; + case PRODUCT_SMALLBUSINESS_SERVER: + edition = "Windows Small Business Server"; + break; + case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM: + edition = "Windows Small Business Server Premium"; + break; + case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE: + edition = "Windows Small Business Server Premium (core installation)"; + break; + case PRODUCT_SOLUTION_EMBEDDEDSERVER: + edition = "Solution Embedded Server"; + break; + case PRODUCT_SOLUTION_EMBEDDEDSERVER_CORE: + edition = "Solution Embedded Server (core installation)"; + break; + case PRODUCT_STANDARD_SERVER: + edition = "Standard Server"; + break; + case PRODUCT_STANDARD_SERVER_CORE: + edition = "Standard Server (core installation)"; + break; + case PRODUCT_STANDARD_SERVER_SOLUTIONS: + edition = "Standard Server Solutions"; + break; + case PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE: + edition = "Standard Server Solutions (core installation)"; + break; + case PRODUCT_STANDARD_SERVER_CORE_V: + edition = "Standard Server without Hyper-V (core installation)"; + break; + case PRODUCT_STANDARD_SERVER_V: + edition = "Standard Server without Hyper-V"; + break; + case PRODUCT_STARTER: + edition = "Starter"; + break; + case PRODUCT_STARTER_N: + edition = "Starter N"; + break; + case PRODUCT_STARTER_E: + edition = "Starter E"; + break; + case PRODUCT_STORAGE_ENTERPRISE_SERVER: + edition = "Enterprise Storage Server"; + break; + case PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE: + edition = "Enterprise Storage Server (core installation)"; + break; + case PRODUCT_STORAGE_EXPRESS_SERVER: + edition = "Express Storage Server"; + break; + case PRODUCT_STORAGE_EXPRESS_SERVER_CORE: + edition = "Express Storage Server (core installation)"; + break; + case PRODUCT_STORAGE_STANDARD_SERVER: + edition = "Standard Storage Server"; + break; + case PRODUCT_STORAGE_STANDARD_SERVER_CORE: + edition = "Standard Storage Server (core installation)"; + break; + case PRODUCT_STORAGE_WORKGROUP_SERVER: + edition = "Workgroup Storage Server"; + break; + case PRODUCT_STORAGE_WORKGROUP_SERVER_CORE: + edition = "Workgroup Storage Server (core installation)"; + break; + case PRODUCT_UNDEFINED: + edition = "Unknown product"; + break; + case PRODUCT_ULTIMATE: + edition = "Ultimate"; + break; + case PRODUCT_ULTIMATE_N: + edition = "Ultimate N"; + break; + case PRODUCT_ULTIMATE_E: + edition = "Ultimate E"; + break; + case PRODUCT_WEB_SERVER: + edition = "Web Server"; + break; + case PRODUCT_WEB_SERVER_CORE: + edition = "Web Server (core installation)"; + break; + } + } + } + #endregion VERSION 6 + } + + s_Edition = edition; + return edition; + } + } + #endregion EDITION + + #region NAME + static private string s_Name; + /// + /// Gets the name of the operating system running on this computer. + /// + static public string Name + { + get + { + if (s_Name != null) + return s_Name; //***** RETURN *****// + + string name = "unknown"; + + OperatingSystem osVersion = Environment.OSVersion; + OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX(); + osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX)); + + if (GetVersionEx(ref osVersionInfo)) + { + int majorVersion = osVersion.Version.Major; + int minorVersion = osVersion.Version.Minor; + + if (majorVersion == 6 && minorVersion == 2) + { + //The registry read workaround is by Scott Vickery. Thanks a lot for the help! + + //http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx + + // For applications that have been manifested for Windows 8.1 & Windows 10. Applications not manifested for 8.1 or 10 will return the Windows 8 OS version value (6.2). + // By reading the registry, we'll get the exact version - meaning we can even compare against Win 8 and Win 8.1. + string exactVersion = RegistryRead(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", ""); + if (!string.IsNullOrEmpty(exactVersion)) + { + string[] splitResult = exactVersion.Split('.'); + majorVersion = Convert.ToInt32(splitResult[0]); + minorVersion = Convert.ToInt32(splitResult[1]); + } + if (IsWindows10()) + { + majorVersion = 10; + minorVersion = 0; + } + } + + switch (osVersion.Platform) + { + case PlatformID.Win32S: + name = "Windows 3.1"; + break; + case PlatformID.WinCE: + name = "Windows CE"; + break; + case PlatformID.Win32Windows: + { + if (majorVersion == 4) + { + string csdVersion = osVersionInfo.szCSDVersion; + switch (minorVersion) + { + case 0: + if (csdVersion == "B" || csdVersion == "C") + name = "Windows 95 OSR2"; + else + name = "Windows 95"; + break; + case 10: + if (csdVersion == "A") + name = "Windows 98 Second Edition"; + else + name = "Windows 98"; + break; + case 90: + name = "Windows Me"; + break; + } + } + break; + } + case PlatformID.Win32NT: + { + byte productType = osVersionInfo.wProductType; + + switch (majorVersion) + { + case 3: + name = "Windows NT 3.51"; + break; + case 4: + switch (productType) + { + case 1: + name = "Windows NT 4.0"; + break; + case 3: + name = "Windows NT 4.0 Server"; + break; + } + break; + case 5: + switch (minorVersion) + { + case 0: + name = "Windows 2000"; + break; + case 1: + name = "Windows XP"; + break; + case 2: + name = "Windows Server 2003"; + break; + } + break; + case 6: + switch (minorVersion) + { + case 0: + switch (productType) + { + case 1: + name = "Windows Vista"; + break; + case 3: + name = "Windows Server 2008"; + break; + } + break; + + case 1: + switch (productType) + { + case 1: + name = "Windows 7"; + break; + case 3: + name = "Windows Server 2008 R2"; + break; + } + break; + case 2: + switch (productType) + { + case 1: + name = "Windows 8"; + break; + case 3: + name = "Windows Server 2012"; + break; + } + break; + case 3: + switch (productType) + { + case 1: + name = "Windows 8.1"; + break; + case 3: + name = "Windows Server 2012 R2"; + break; + } + break; + } + break; + case 10: + switch (minorVersion) + { + case 0: + switch (productType) + { + case 1: + name = "Windows 10"; + break; + case 3: + name = "Windows Server 2016"; + break; + } + break; + } + break; + } + break; + } + } + } + + s_Name = name; + return name; + } + } + #endregion NAME + + #region PINVOKE + + #region GET + #region PRODUCT INFO + [DllImport("Kernel32.dll")] + internal static extern bool GetProductInfo( + int osMajorVersion, + int osMinorVersion, + int spMajorVersion, + int spMinorVersion, + out int edition); + #endregion PRODUCT INFO + + #region VERSION + [DllImport("kernel32.dll")] + private static extern bool GetVersionEx(ref OSVERSIONINFOEX osVersionInfo); + #endregion VERSION + + #region SYSTEMMETRICS + [DllImport("user32")] + public static extern int GetSystemMetrics(int nIndex); + #endregion SYSTEMMETRICS + + #region SYSTEMINFO + [DllImport("kernel32.dll")] + public static extern void GetSystemInfo([MarshalAs(UnmanagedType.Struct)] ref SYSTEM_INFO lpSystemInfo); + + [DllImport("kernel32.dll")] + public static extern void GetNativeSystemInfo([MarshalAs(UnmanagedType.Struct)] ref SYSTEM_INFO lpSystemInfo); + #endregion SYSTEMINFO + + #endregion GET + + #region OSVERSIONINFOEX + [StructLayout(LayoutKind.Sequential)] + private struct OSVERSIONINFOEX + { + public int dwOSVersionInfoSize; + public int dwMajorVersion; + public int dwMinorVersion; + public int dwBuildNumber; + public int dwPlatformId; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] + public string szCSDVersion; + public short wServicePackMajor; + public short wServicePackMinor; + public short wSuiteMask; + public byte wProductType; + public byte wReserved; + } + #endregion OSVERSIONINFOEX + + #region SYSTEM_INFO + [StructLayout(LayoutKind.Sequential)] + public struct SYSTEM_INFO + { + internal _PROCESSOR_INFO_UNION uProcessorInfo; + public uint dwPageSize; + public IntPtr lpMinimumApplicationAddress; + public IntPtr lpMaximumApplicationAddress; + public IntPtr dwActiveProcessorMask; + public uint dwNumberOfProcessors; + public uint dwProcessorType; + public uint dwAllocationGranularity; + public ushort dwProcessorLevel; + public ushort dwProcessorRevision; + } + #endregion SYSTEM_INFO + + #region _PROCESSOR_INFO_UNION + [StructLayout(LayoutKind.Explicit)] + public struct _PROCESSOR_INFO_UNION + { + [FieldOffset(0)] + internal uint dwOemId; + [FieldOffset(0)] + internal ushort wProcessorArchitecture; + [FieldOffset(2)] + internal ushort wReserved; + } + #endregion _PROCESSOR_INFO_UNION + + #region 64 BIT OS DETECTION + [DllImport("kernel32", SetLastError = true, CallingConvention = CallingConvention.Winapi)] + public extern static IntPtr LoadLibrary(string libraryName); + + [DllImport("kernel32", SetLastError = true, CallingConvention = CallingConvention.Winapi)] + public extern static IntPtr GetProcAddress(IntPtr hwnd, string procedureName); + #endregion 64 BIT OS DETECTION + + #region PRODUCT + private const int PRODUCT_UNDEFINED = 0x00000000; + private const int PRODUCT_ULTIMATE = 0x00000001; + private const int PRODUCT_HOME_BASIC = 0x00000002; + private const int PRODUCT_HOME_PREMIUM = 0x00000003; + private const int PRODUCT_ENTERPRISE = 0x00000004; + private const int PRODUCT_HOME_BASIC_N = 0x00000005; + private const int PRODUCT_BUSINESS = 0x00000006; + private const int PRODUCT_STANDARD_SERVER = 0x00000007; + private const int PRODUCT_DATACENTER_SERVER = 0x00000008; + private const int PRODUCT_SMALLBUSINESS_SERVER = 0x00000009; + private const int PRODUCT_ENTERPRISE_SERVER = 0x0000000A; + private const int PRODUCT_STARTER = 0x0000000B; + private const int PRODUCT_DATACENTER_SERVER_CORE = 0x0000000C; + private const int PRODUCT_STANDARD_SERVER_CORE = 0x0000000D; + private const int PRODUCT_ENTERPRISE_SERVER_CORE = 0x0000000E; + private const int PRODUCT_ENTERPRISE_SERVER_IA64 = 0x0000000F; + private const int PRODUCT_BUSINESS_N = 0x00000010; + private const int PRODUCT_WEB_SERVER = 0x00000011; + private const int PRODUCT_CLUSTER_SERVER = 0x00000012; + private const int PRODUCT_HOME_SERVER = 0x00000013; + private const int PRODUCT_STORAGE_EXPRESS_SERVER = 0x00000014; + private const int PRODUCT_STORAGE_STANDARD_SERVER = 0x00000015; + private const int PRODUCT_STORAGE_WORKGROUP_SERVER = 0x00000016; + private const int PRODUCT_STORAGE_ENTERPRISE_SERVER = 0x00000017; + private const int PRODUCT_SERVER_FOR_SMALLBUSINESS = 0x00000018; + private const int PRODUCT_SMALLBUSINESS_SERVER_PREMIUM = 0x00000019; + private const int PRODUCT_HOME_PREMIUM_N = 0x0000001A; + private const int PRODUCT_ENTERPRISE_N = 0x0000001B; + private const int PRODUCT_ULTIMATE_N = 0x0000001C; + private const int PRODUCT_WEB_SERVER_CORE = 0x0000001D; + private const int PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT = 0x0000001E; + private const int PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY = 0x0000001F; + private const int PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING = 0x00000020; + private const int PRODUCT_SERVER_FOUNDATION = 0x00000021; + private const int PRODUCT_HOME_PREMIUM_SERVER = 0x00000022; + private const int PRODUCT_SERVER_FOR_SMALLBUSINESS_V = 0x00000023; + private const int PRODUCT_STANDARD_SERVER_V = 0x00000024; + private const int PRODUCT_DATACENTER_SERVER_V = 0x00000025; + private const int PRODUCT_ENTERPRISE_SERVER_V = 0x00000026; + private const int PRODUCT_DATACENTER_SERVER_CORE_V = 0x00000027; + private const int PRODUCT_STANDARD_SERVER_CORE_V = 0x00000028; + private const int PRODUCT_ENTERPRISE_SERVER_CORE_V = 0x00000029; + private const int PRODUCT_HYPERV = 0x0000002A; + private const int PRODUCT_STORAGE_EXPRESS_SERVER_CORE = 0x0000002B; + private const int PRODUCT_STORAGE_STANDARD_SERVER_CORE = 0x0000002C; + private const int PRODUCT_STORAGE_WORKGROUP_SERVER_CORE = 0x0000002D; + private const int PRODUCT_STORAGE_ENTERPRISE_SERVER_CORE = 0x0000002E; + private const int PRODUCT_STARTER_N = 0x0000002F; + private const int PRODUCT_PROFESSIONAL = 0x00000030; + private const int PRODUCT_PROFESSIONAL_N = 0x00000031; + private const int PRODUCT_SB_SOLUTION_SERVER = 0x00000032; + private const int PRODUCT_SERVER_FOR_SB_SOLUTIONS = 0x00000033; + private const int PRODUCT_STANDARD_SERVER_SOLUTIONS = 0x00000034; + private const int PRODUCT_STANDARD_SERVER_SOLUTIONS_CORE = 0x00000035; + private const int PRODUCT_SB_SOLUTION_SERVER_EM = 0x00000036; + private const int PRODUCT_SERVER_FOR_SB_SOLUTIONS_EM = 0x00000037; + private const int PRODUCT_SOLUTION_EMBEDDEDSERVER = 0x00000038; + private const int PRODUCT_SOLUTION_EMBEDDEDSERVER_CORE = 0x00000039; + //private const int ???? = 0x0000003A; + private const int PRODUCT_ESSENTIALBUSINESS_SERVER_MGMT = 0x0000003B; + private const int PRODUCT_ESSENTIALBUSINESS_SERVER_ADDL = 0x0000003C; + private const int PRODUCT_ESSENTIALBUSINESS_SERVER_MGMTSVC = 0x0000003D; + private const int PRODUCT_ESSENTIALBUSINESS_SERVER_ADDLSVC = 0x0000003E; + private const int PRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE = 0x0000003F; + private const int PRODUCT_CLUSTER_SERVER_V = 0x00000040; + private const int PRODUCT_EMBEDDED = 0x00000041; + private const int PRODUCT_STARTER_E = 0x00000042; + private const int PRODUCT_HOME_BASIC_E = 0x00000043; + private const int PRODUCT_HOME_PREMIUM_E = 0x00000044; + private const int PRODUCT_PROFESSIONAL_E = 0x00000045; + private const int PRODUCT_ENTERPRISE_E = 0x00000046; + private const int PRODUCT_ULTIMATE_E = 0x00000047; + //private const int PRODUCT_UNLICENSED = 0xABCDABCD; + #endregion PRODUCT + + #region VERSIONS + private const int VER_NT_WORKSTATION = 1; + private const int VER_NT_DOMAIN_CONTROLLER = 2; + private const int VER_NT_SERVER = 3; + private const int VER_SUITE_SMALLBUSINESS = 1; + private const int VER_SUITE_ENTERPRISE = 2; + private const int VER_SUITE_TERMINAL = 16; + private const int VER_SUITE_DATACENTER = 128; + private const int VER_SUITE_SINGLEUSERTS = 256; + private const int VER_SUITE_PERSONAL = 512; + private const int VER_SUITE_BLADE = 1024; + #endregion VERSIONS + + #endregion PINVOKE + + #region SERVICE PACK + /// + /// Gets the service pack information of the operating system running on this computer. + /// + static public string ServicePack + { + get + { + string servicePack = String.Empty; + OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX(); + + osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX)); + + if (GetVersionEx(ref osVersionInfo)) + { + servicePack = osVersionInfo.szCSDVersion; + } + + return servicePack; + } + } + #endregion SERVICE PACK + + #region VERSION + #region BUILD + /// + /// Gets the build version number of the operating system running on this computer. + /// + static public int BuildVersion + { + get + { + return int.Parse(RegistryRead(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuildNumber", "0")); + } + } + #endregion BUILD + + #region FULL + #region STRING + /// + /// Gets the full version string of the operating system running on this computer. + /// + static public string VersionString + { + get + { + return Version.ToString(); + } + } + #endregion STRING + + #region VERSION + /// + /// Gets the full version of the operating system running on this computer. + /// + static public Version Version + { + get + { + return new Version(MajorVersion, MinorVersion, BuildVersion, RevisionVersion); + } + } + #endregion VERSION + #endregion FULL + + #region MAJOR + /// + /// Gets the major version number of the operating system running on this computer. + /// + static public int MajorVersion + { + get + { + if(IsWindows10()) + { + return 10; + } + string exactVersion = RegistryRead(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", ""); + if(!string.IsNullOrEmpty(exactVersion)) + { + string[] splitVersion = exactVersion.Split('.'); + return int.Parse(splitVersion[0]); + } + return Environment.OSVersion.Version.Major; + } + } + #endregion MAJOR + + #region MINOR + /// + /// Gets the minor version number of the operating system running on this computer. + /// + static public int MinorVersion + { + get + { + if (IsWindows10()) + { + return 0; + } + string exactVersion = RegistryRead(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", ""); + if (!string.IsNullOrEmpty(exactVersion)) + { + string[] splitVersion = exactVersion.Split('.'); + return int.Parse(splitVersion[1]); + } + return Environment.OSVersion.Version.Minor; + } + } + #endregion MINOR + + #region REVISION + /// + /// Gets the revision version number of the operating system running on this computer. + /// + static public int RevisionVersion + { + get + { + if(IsWindows10()) + { + return 0; + } + return Environment.OSVersion.Version.Revision; + } + } + #endregion REVISION + #endregion VERSION + + #region 64 BIT OS DETECTION + private static IsWow64ProcessDelegate GetIsWow64ProcessDelegate() + { + IntPtr handle = LoadLibrary("kernel32"); + + if (handle != IntPtr.Zero) + { + IntPtr fnPtr = GetProcAddress(handle, "IsWow64Process"); + + if (fnPtr != IntPtr.Zero) + { + return (IsWow64ProcessDelegate)Marshal.GetDelegateForFunctionPointer((IntPtr)fnPtr, typeof(IsWow64ProcessDelegate)); + } + } + + return null; + } + + private static bool Is32BitProcessOn64BitProcessor() + { + IsWow64ProcessDelegate fnDelegate = GetIsWow64ProcessDelegate(); + + if (fnDelegate == null) + { + return false; + } + + bool isWow64; + bool retVal = fnDelegate.Invoke(Process.GetCurrentProcess().Handle, out isWow64); + + if (retVal == false) + { + return false; + } + + return isWow64; + } + #endregion 64 BIT OS DETECTION + + #region Windows 10 Detection + + private static bool IsWindows10() + { + string productName = RegistryRead(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", ""); + if (productName.StartsWith("Windows 10", StringComparison.OrdinalIgnoreCase)) + { + return true; + } + return false; + } + + #endregion + + #region Registry Methods + + private static string RegistryRead(string RegistryPath, string Field, string DefaultValue) + { + string rtn = ""; + string backSlash = ""; + string newRegistryPath = ""; + + try + { + RegistryKey OurKey = null; + string[] split_result = RegistryPath.Split('\\'); + + if (split_result.Length > 0) + { + split_result[0] = split_result[0].ToUpper(); // Make the first entry uppercase... + + if (split_result[0] == "HKEY_CLASSES_ROOT") OurKey = Registry.ClassesRoot; + else if (split_result[0] == "HKEY_CURRENT_USER") OurKey = Registry.CurrentUser; + else if (split_result[0] == "HKEY_LOCAL_MACHINE") OurKey = Registry.LocalMachine; + else if (split_result[0] == "HKEY_USERS") OurKey = Registry.Users; + else if (split_result[0] == "HKEY_CURRENT_CONFIG") OurKey = Registry.CurrentConfig; + + if (OurKey != null) + { + for (int i = 1; i < split_result.Length; i++) + { + newRegistryPath += backSlash + split_result[i]; + backSlash = "\\"; + } + + if (newRegistryPath != "") + { + //rtn = (string)Registry.GetValue(RegistryPath, "CurrentVersion", DefaultValue); + + OurKey = OurKey.OpenSubKey(newRegistryPath); + rtn = (string)OurKey.GetValue(Field, DefaultValue); + OurKey.Close(); + } + } + } + } + catch { } + + return rtn; + } + + #endregion Registry Methods + } +} diff --git a/OSVersionInfoDLL/OSVersionInfoDLL.csproj b/OSVersionInfoDLL/OSVersionInfoDLL.csproj new file mode 100644 index 0000000..6586a34 --- /dev/null +++ b/OSVersionInfoDLL/OSVersionInfoDLL.csproj @@ -0,0 +1,89 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {9599DF4F-9D56-4448-8F56-76B3966982A4} + Library + Properties + JCS + OSVersionInfo + v2.0 + 512 + + + + + + + 3.5 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + + 3.5 + + + 3.5 + + + + + + + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + \ No newline at end of file diff --git a/OSVersionInfoDLL/Properties/AssemblyInfo.cs b/OSVersionInfoDLL/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6cc03ab --- /dev/null +++ b/OSVersionInfoDLL/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("OSVersionInfoDLL")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OSVersionInfoDLL")] +[assembly: AssemblyCopyright("Copyright © 2010-2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a3be4af5-b38a-442d-a0a8-8c63450c2888")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("3.0.0.0")] +[assembly: AssemblyFileVersion("3.0.0.0")] diff --git a/OSVersionInfoDLL/Properties/Resources.Designer.cs b/OSVersionInfoDLL/Properties/Resources.Designer.cs new file mode 100644 index 0000000..ba26196 --- /dev/null +++ b/OSVersionInfoDLL/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace JCS.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("JCS.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/OSVersionInfoDLL/Properties/Resources.resx b/OSVersionInfoDLL/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/OSVersionInfoDLL/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/OSVersionInfoDLL/Properties/Settings.Designer.cs b/OSVersionInfoDLL/Properties/Settings.Designer.cs new file mode 100644 index 0000000..9699ff6 --- /dev/null +++ b/OSVersionInfoDLL/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace JCS.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/OSVersionInfoDLL/Properties/Settings.settings b/OSVersionInfoDLL/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/OSVersionInfoDLL/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/OSVersionInfoDLL/app.config b/OSVersionInfoDLL/app.config new file mode 100644 index 0000000..ea93c85 --- /dev/null +++ b/OSVersionInfoDLL/app.config @@ -0,0 +1,3 @@ + + +