locked
Why we will get different output when same application will be run on VS2008 and VS2010? RRS feed

  • Question

  • Hello sir I have a sample code snippet in which I would like to know which version office version is instaaled on client system. This is a simple console based application in which we display different version of office found at client machine. When I will execute same code snippet on VS2008 then different output is displayed and when we run same code snippet on VS2010 then different output is displayed. I would like to know why this is happened or what mistake I had did. The code snippet is as follows.

    Code sniipet.

    using

     

    System;

    using

     

    System.Collections.Generic;

    using

     

    System.Linq;

    using

     

    System.Text;

    using

     

    Microsoft.Win32;

    namespace

     

    Test

    {

     

    class

    Program

    {

     

    static void Main(string

    [] args)

    {

     

    Console.WriteLine(CheckOfficeVersion1

    .getOfficeVersion().Count);

    }

    }

     

    public class

    CheckOfficeVersion1

    {

     

    private const string reg_office_key = @"SOFTWARE\Microsoft\Office"

    ;

     

    public static List<string

    []> getOfficeVersion()

    {

     

    List<string[]> installedOfficeVersion = null

    ;

     

    try

    {

     

    RegistryKey reg_office = Registry.LocalMachine.OpenSubKey(reg_office_key, false

    );

     

    if (reg_office != null

    )

    {

    installedOfficeVersion =

    new List<string

    []>();

     

    string

    [] reg_office_name = reg_office.GetSubKeyNames();

     

    string[] off_details = new string

    [2];

     

    foreach (string temp in

    reg_office_name)

    {

     

    switch

    (temp)

    {

     

    case "7.0"

    :

     

    Console.WriteLine("Office 95"

    );

    off_details[0] =

    "chkAPOffice95"

    ;

    off_details[1] =

    "Office 95"

    ;

    installedOfficeVersion.Add(off_details);

     

    break

    ;

     

    case "8.0"

    :

     

    Console.WriteLine("Office 97/98"

    );

    off_details[0] =

    "chkAPOffice97"

    ;

    off_details[1] =

    "Office 97/98"

    ;

    installedOfficeVersion.Add(off_details);

     

    break

    ;

     

    case "9.0"

    :

     

    Console.WriteLine("Office 2000"

    );

    off_details[0] =

    "chkAPOffice2000"

    ;

    off_details[1] =

    "Office 2000"

    ;

    installedOfficeVersion.Add(off_details);

     

    break

    ;

     

    case "10.0"

    :

     

    Console.WriteLine("Office 2002"

    );

    off_details[0] =

    "chkAPOffice2002"

    ;

    off_details[1] =

    "Office 2002"

    ;

    installedOfficeVersion.Add(off_details);

     

    break

    ;

     

    case "11.0"

    :

     

    Console.WriteLine("Office 2003"

    );

    off_details[0] =

    "chkAPOffice2003"

    ;

    off_details[1] =

    "Office 2003"

    ;

    installedOfficeVersion.Add(off_details);

     

    break

    ;

     

    case "12.0"

    :

     

    Console.WriteLine("Office 2007"

    );

    off_details[0] =

    "chkAPOffice2007"

    ;

    off_details[1] =

    "Office 2007"

    ;

    installedOfficeVersion.Add(off_details);

     

    break

    ;

     

    case "14.0"

    :

     

    Console.WriteLine("Office 2010"

    );

    off_details[0] =

    "chkAPOffice2010"

    ;

    off_details[1] =

    "Office 2010"

    ;

    installedOfficeVersion.Add(off_details);

     

    break

    ;

    }

    }

    }

    }

     

    catch (Exception

    ex)

    {

     

    }

     

    return

    installedOfficeVersion;

    }

    }

    }

    Wednesday, March 23, 2011 3:43 PM