Click here to Skip to main content
15,891,375 members
Home / Discussions / C#
   

C#

 
GeneralRe: What connection strings does the DbConnection class support? Pin
Christopher Stratmann11-Apr-10 3:07
Christopher Stratmann11-Apr-10 3:07 
GeneralRe: What connection strings does the DbConnection class support? Pin
PIEBALDconsult11-Apr-10 4:34
mvePIEBALDconsult11-Apr-10 4:34 
QuestionAsynchronous download [modified] Pin
Sunil G10-Apr-10 8:46
Sunil G10-Apr-10 8:46 
AnswerRe: Asynchronous download Pin
Christopher Stratmann10-Apr-10 10:30
Christopher Stratmann10-Apr-10 10:30 
AnswerRe: Asynchronous download Pin
Eddy Vluggen10-Apr-10 23:45
professionalEddy Vluggen10-Apr-10 23:45 
GeneralRe: Asynchronous download Pin
Sunil G30-Apr-10 20:45
Sunil G30-Apr-10 20:45 
GeneralRe: Asynchronous download Pin
Eddy Vluggen1-May-10 0:56
professionalEddy Vluggen1-May-10 0:56 
QuestionGet Office 10.0 product key from the registry Pin
Member 667796910-Apr-10 7:39
Member 667796910-Apr-10 7:39 
RegEdit Copy Key Name for Microsoft Office 10.0 is "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0". So why is registry equal to null in "registry = Registry.LocalMachine.OpenSubKey( @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0", false);" in the following C# 2008 code?

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace MSKeyFinder
{
    public partial class frmMain : Form
    {
        //
        // Drop shadow for forms
        //
        private const int CS_DROPSHADOW = 0x00020000;
        
        public frmMain()
        {
            InitializeComponent();
        }

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams p = base.CreateParams;
                p.ClassStyle |= CS_DROPSHADOW;
                return p;
            }
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {
            byte[] digitalProductId = null;
            RegistryKey registry = null;

            try
            {
                registry = Registry.LocalMachine.OpenSubKey(
                    @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0", false);
            }
            catch (System.Exception ex)
            {
                string caption = "Error";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                MessageBoxIcon icon = MessageBoxIcon.Error;
                MessageBox.Show(ex.Message, caption, buttons, icon);
                Environment.Exit(0);
            }
            finally
            {
                if (registry == null)
                {
                    string message = "Microsoft Office (TM) XP not installed or error\r\n" +
                        "reading Registry (Registry.LocalMachine.OpenSubKey returned null).";
                    string caption = "Error";
                    MessageBoxButtons buttons = MessageBoxButtons.OK;
                    MessageBoxIcon icon = MessageBoxIcon.Error;
                    MessageBox.Show(message, caption, buttons, icon);
                    Environment.Exit(0);
                }
                else
                {
                    registry.Close();
                    lblOffVersion.Text = (string)"Microsoft Office (TM) 2002";
                    digitalProductId = registry.GetValue("DigitalProductID") as byte[];
                    lblOffiProductKey.Text = (string)DecodeProductKey(digitalProductId);
                }
            }
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            About dlgForm1 = new About();
            dlgForm1.ShowDialog();
        }
        
        public static byte[] GetRegistryDigitalProductID()
        {
            byte[] digitalProductId = null;
            RegistryKey registry = null; ;
            
            try
            {
                registry = Registry.LocalMachine.OpenSubKey(
                    @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\10.0\Registration\" +
                        @"{91110409-6000-11D3-8CFE-0050048383C9}", false);
            }
            catch (System.Exception ex)
            {
                registry.Close();
                string caption = "Error";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                MessageBoxIcon icon = MessageBoxIcon.Error;
                MessageBox.Show(ex.Message, caption, buttons, icon);
                Environment.Exit(0);
            }
            finally
            {
                if (registry == null)
                {
                    registry.Close();
                    string message = "Microsoft Office (TM) XP not installed or error\r\n" +
                        "reading Registry (Registry.LocalMachine.OpenSubKey returned null).";
                    string caption = "Error";
                    MessageBoxButtons buttons = MessageBoxButtons.OK;
                    MessageBoxIcon icon = MessageBoxIcon.Error;
                    MessageBox.Show(message, caption, buttons, icon);
                    Environment.Exit(0);
                }
                else
                {
                    digitalProductId = registry.GetValue("DigitalProductID") as byte[];
                    registry.Close();
                }
            }

            return digitalProductId;
        }
        
        public static string DecodeProductKey(byte[] digitalProductId)
        {
            //
            // Offset of first byte of encoded product key in 'DigitalProductIdxxx" 
            // REG_BINARY value. Offset = 34H.
            //
            const int keyStartIndex = 52;
            
            //
            // Offset of last byte of encoded product key in 'DigitalProductIdxxx" 
            // REG_BINARY value. Offset = 43H.
            //
            const int keyEndIndex = keyStartIndex + 15;
            
            //
            // Possible alpha-numeric characters in product key.
            //
            char[] digits = new char[]
            {
                'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'P', 'Q', 'R', 
                'T', 'V', 'W', 'X', 'Y', '2', '3', '4', '6', '7', '8', '9',
            };
            
            //
            // Length of decoded product key.
            //
            const int decodeLength = 29;
            
            //
            // Length of decoded product key in byte-form. Each byte represents 2 chars.
            //
            const int decodeStringLength = 15;
            
            //
            // Array of containing the decoded product key.
            //
            char[] decodedChars = new char[decodeLength];
            
            //
            // Extract byte 52 to 67 inclusive.
            //
            ArrayList hexPid = new ArrayList();
            
            for (int i = keyStartIndex; i <= keyEndIndex; i++)
            {
                hexPid.Add(digitalProductId[i]);
            }
            
            for (int i = decodeLength - 1; i >= 0; i--)
            {
                //
                // Every sixth char is a separator.
                //
                if ((i + 1) % 6 == 0)
                {
                    decodedChars[i] = '-';
                }
                else
                {
                    //
                    // Do the actual decoding.
                    //
                    int digitMapIndex = 0;
                    
                    for (int j = decodeStringLength - 1; j >= 0; j--)
                    {
                        int byteValue = (digitMapIndex << 8) | (byte)hexPid[j];
                        hexPid[j] = (byte)(byteValue / 24);
                        digitMapIndex = byteValue % 24;
                        decodedChars[i] = digits[digitMapIndex];
                    }
                }
            }
            return new string(decodedChars);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            toolStripStatusLabel1.Text = DateTime.Now.ToShortTimeString();
        }
    }
}

AnswerRe: Get Office 10.0 product key from the registry Pin
spicture10-Apr-10 9:57
spicture10-Apr-10 9:57 
GeneralRe: Get Office 10.0 product key from the registry Pin
Not Active10-Apr-10 10:23
mentorNot Active10-Apr-10 10:23 
GeneralRe: Get Office 10.0 product key from the registry Pin
harold aptroot10-Apr-10 10:49
harold aptroot10-Apr-10 10:49 
AnswerRe: Get Office 10.0 product key from the registry Pin
Eddy Vluggen10-Apr-10 22:57
professionalEddy Vluggen10-Apr-10 22:57 
Questionsql connection pool feature Pin
teknolog12310-Apr-10 5:37
teknolog12310-Apr-10 5:37 
AnswerRe: sql connection pool feature Pin
Abhinav S10-Apr-10 5:43
Abhinav S10-Apr-10 5:43 
GeneralRe: sql connection pool feature Pin
teknolog12310-Apr-10 5:51
teknolog12310-Apr-10 5:51 
AnswerRe: sql connection pool feature Pin
PIEBALDconsult10-Apr-10 5:57
mvePIEBALDconsult10-Apr-10 5:57 
AnswerRe: sql connection pool feature Pin
Eddy Vluggen10-Apr-10 22:49
professionalEddy Vluggen10-Apr-10 22:49 
Questionsetting datasource of Grid View Problem Pin
shaina223110-Apr-10 2:07
shaina223110-Apr-10 2:07 
GeneralRe: setting datasource of Grid View Problem Pin
Khaniya10-Apr-10 2:38
professionalKhaniya10-Apr-10 2:38 
GeneralRe: setting datasource of Grid View Problem Pin
shaina223110-Apr-10 2:53
shaina223110-Apr-10 2:53 
AnswerRe: setting datasource of Grid View Problem Pin
Khaniya10-Apr-10 23:04
professionalKhaniya10-Apr-10 23:04 
QuestionError while uploading large file Pin
sjs4u9-Apr-10 20:16
sjs4u9-Apr-10 20:16 
AnswerRe: Error while uploading large file Pin
Not Active10-Apr-10 1:05
mentorNot Active10-Apr-10 1:05 
GeneralRe: Error while uploading large file [modified] Pin
sjs4u10-Apr-10 1:31
sjs4u10-Apr-10 1:31 
GeneralRe: Error while uploading large file Pin
Not Active10-Apr-10 2:02
mentorNot Active10-Apr-10 2:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.