コード例 #1
0
        /// <summary>
        /// Event handler that is fired when this form is shown.
        /// Changes window title and gets current Windows Product Key.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_Shown(object sender, EventArgs e)
        {
            // get the assembly information to display current version in the title of the window
            var assemblyName = AssemblyName.GetAssemblyName(Assembly.GetExecutingAssembly().Location);

            // format window title text (append version to the current title)
            Text = $@"{Text} v{assemblyName.Version.Major}.{assemblyName.Version.Minor}";

            // get the current Windows Product Key and display it
            tbWindowsProductKey.Text = KeyDecoder.GetWindowsProductKeyFromRegistry();
        }
コード例 #2
0
        /// <summary>
        /// Event handler that decodes DigitalProductId and shows result in ProductKey textbox.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnParseDigitalProductId_Click(object sender, EventArgs e)
        {
            // Try to decode input string and detect, if the string is in expected format.
            // Maybe some regex would do it better? ;)
            //

            // let wrap everything we do with input string into try/catch to display error
            // message when anything fails
            try
            {
                // First try to split the string into the key and value
                var keyValue = tbDigitalProductId.Text.Trim().Split('=');

                // Get the key
                var key = keyValue[0].Trim();

                // Is this a valid key
                if (!key.Equals("\"DigitalProductId\""))
                {
                    SetParseErrorMessage();
                    return;
                }

                // Get the value and remove unwanted characters...
                var value = keyValue[1].Replace("\\\r\n", "").Replace(" ", "").Trim();

                // Regedit hex value?
                if (!value.StartsWith("hex:", StringComparison.InvariantCultureIgnoreCase))
                {
                    SetParseErrorMessage();
                    return;
                }

                // Convert comma delimited string hex values into byte array
                var hexValues = value.Remove(0, 4).Split(',');

                // crete byte array from hex values
                var byteValues = hexValues.Select(s => Convert.ToByte(s.ToUpper(), 16)).ToArray();
                tbProductKey.Text = KeyDecoder.GetWindowsProductKeyFromDigitalProductId(
                    byteValues,
                    cbDigitalProductIdVersion.SelectedIndex == 0
                        ? DigitalProductIdVersion.UpToWindows7
                        : DigitalProductIdVersion.Windows8AndUp);
                btnCopyToClipboard.Enabled = true;
            }
            catch (Exception)
            {
                SetParseErrorMessage();
            }
        }
コード例 #3
0
 private void GetKey()
 {
     tbWindowsProductKey.Text = KeyDecoder.GetWindowsProductKey();
     tbOfficeProductKey.Text  = KeyDecoder.GetOfficeProductKey();
 }