0
votes

I have installed Microsoft Office 2010 the location is
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14"
I need to dynamically load an assembly from this location.
Is it possible to get the location "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14" programmatically?

2
how about saving the path on a config file or as a environment variable.Prabhu Murthy
@CodeIgnoto, I need to get the location of Office PIA in any machine.sharmila
@CodeIgnoto, Can you pleaes tell me how can I get it using registry?sharmila

2 Answers

2
votes

Here is the WMI query to retrieve the installation path.You will have to pass the program name after the like clause in the WMI query.Since i didnt know the program name,i have used a like clause.If you know the exact program name use it along with "=" operator.

Add a reference to the DLL (System.Management).

Using System.Management

    ManagementObjectSearcher WMIQuery = new ManagementObjectSearcher("SELECT * FROM Win32_Product WHERE CAPTION LIKE \"%office%\" ");
    ManagementObjectCollection WMIQueryCollection = WMIQuery.Get();

    foreach (ManagementObject MO in WMIQueryCollection)
    {
        Console.WriteLine("Caption : " + MO["Caption"].ToString());
        Console.WriteLine("InstallLocation : " + (MO["InstallLocation"] == null ? " " : MO["InstallLocation"].ToString()));
    }

Here is the MSDN link that will get you started with writing WMI queries(WQL).
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394606(v=vs.85).aspx

0
votes

As far as I could understand, you need to find where Office is installed. If yes, then Windows Management Instrumentation will help you. It's an API that lets you query the system for data like installed software, available resources etc.

Look here for more info: Get installed applications in a system