3 Replies - 27432 Views - Last Post: 23 September 2007 - 03:17 PM Rate Topic: -----

#1 marcells23   User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 143
  • Joined: 22-August 07

Check for MS Office ProductID

Posted 22 September 2007 - 07:15 PM

Is there any way in C# to directly get the version of MS office that is installed?
I know that it is listed in the registry but there can be more than one version installed..
I need to get the MS office version and then the DigitalProductID of that version for inventory.

i know its located at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Registration\
and 11.0 being different for each version..

i've been using
				RegistryKey myReg = Registry.LocalMachine.OpenSubKey(@"\SOFTWARE\Microsoft\Office\11.0\Registration\guid...");

				System.Byte[] prodID = (System.Byte[])myReg.GetValue("DigitalProductID");
				myReg.Close();



but i cant find a way to search through the registry with and match up each version because we have small business, pro, and standard for xp and 2003 on random computers..
any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: Check for MS Office ProductID

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Check for MS Office ProductID

Posted 22 September 2007 - 07:40 PM

Well I did some testing, and this is the easiest way I've found to do it.

First you need this reference:

using Microsoft.Office.Interop;



Then I created this method, which returned the version I was running:

public string GetOfficeVersion()
{
	string sVersion = string.Empty;
		Microsoft.Office.Interop.Word.Application appVersion = new Microsoft.Office.Interop.Word.Application();
		appVersion.Visible = false;
		switch (appVersion.Version.ToString())
		{
			case "7.0":
				sVersion = "95";
				break;
			case "8.0":
				sVersion = "97";
				break;
			case "9.0":
				sVersion = "2000";
				break;
			case "10.0":
				sVersion = "2002";
				break;
			case "11.0":
				sVersion = "2003";
				break;
			case "12.0":
				sVersion = "2007";
				break;
			default:
				sVersion = "Too Old!";
				break;
		}
					  
			appVersion.Quit
			appVersion = null;
			return sVersion;
}



Hope that helps! :)

<Edit>I forgot to remove the ref a, ref b, ref a from the Quit() call</edit>

This post has been edited by PsychoCoder: 22 September 2007 - 07:48 PM

Was This Post Helpful? 0
  • +
  • -

#3 marcells23   User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 143
  • Joined: 22-August 07

Re: Check for MS Office ProductID

Posted 22 September 2007 - 07:43 PM

Thanks PyschoCoder..that was exactly what i was looking for..i didnt even know that existed.. :)
Was This Post Helpful? 0
  • +
  • -

#4 marcells23   User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 143
  • Joined: 22-August 07

Re: Check for MS Office ProductID

Posted 23 September 2007 - 03:17 PM

Nevermind:( it doesnt work.. its returning the version but unless the computer that it is being run on has the same version of office as the reference i added it doesnt work..

btw im using Microsoft Word 11.0 Object Library..not sure if theres something i did wrong...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1