I have to do it in C#.
How can i check if Microsoft Office is installed?
I have to do it in C#.
How can i check if Microsoft Office is installed?
If you don't need a specific Office version present, you can check by looking up the App Path to one of the office apps (winword.exe for instance):
private static bool IsOfficeInstalled()
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Winword.exe");
if (key!= null)
{
key.Close();
}
return key != null;
}
You could root around in the registry:-
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\nn.n\Word\InstallRoot
The nn.n will be the version installed 11.0 or 12.00
try to create the object with the version in it and if it throws out error, it is evident that the MSOffice you are looking for is not installed.
Try some thing like the below
try
{
//try creating the object here.
}
catch(Exception ex)
{
// You can decide that the 3rd party instance required is not installed
}
Because all the clients would not give you the permission to read the registry
If it is specific MS Office applications you are looking for you could do something like:
public enum MSOfficeApplications
{
Access,
Excel,
Word
}
public bool IsInstalled(MSOfficeApplications app)
{
var keyName = String.Empty;
switch (app)
{
case MSOfficeApplications.Access:
regKey = "Access.Application";
case MSOfficeApplications.Excel:
regKey = "Excel.Application";
case MSOfficeApplications.Word:
regKey = "Word.Application";
}
RegistryKey key = Registry.ClassesRoot;
RegistryKey subKey = key.OpenSubKey(keyName);
return not (subKey == null);
}