views:

598

answers:

3

I am building a C# application that exports a CSV file to be used with the Visio org chart wizard.

How can I check that an installation of Visio exists, and what path?

The most obvious method is checking if C:\Program Files\Office12\ORGWIZ.EXE exists, but that is fairly dependant on having Visio 2007 installed..

My other thought is checking the registry, but what is the most reliable source? I've looked under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ where there are version numbers, but underneath them is a Visio\InstallRoot which would be perfect except for checking each versions..

I read elsewhere that I could check Uninstall information under Software\Microsoft\Windows\CurrentVersion\Uninstall\, but that looks fairly complicated for Windows components...

+1  A: 

Could you just check if the Visio file extension is registered, and to what application?

http://www.dreamincode.net/code/snippet3159.htm

Look in HKEY_CLASSES_ROOT\\.vsd, does the key exist, what are the values? Compare them to a set of values which indicate the application is installed.

marcc
Yes, that key is there.. There is not much in the way of values to connect it to an installation - the `PersistentHandler` hash doesn't match anything else in the registry (I was hoping it was under the uninstall info)..
brass-kazoo
On my computer, the default value for the key is a REG_SZ with the value "Visio.Drawing.11"
marcc
Just got to that :) - HKLM\SOFTWARE\Classes\Visio.Drawing.11\protocol\server leads me to a visio.exe path!
brass-kazoo
+3  A: 

I would do a lookup for HKEY_CLASSES_ROOT\Visio.Application in the registry. If it doesn't exist, no install. If it does exist, the CurVer sub key will give you something like Visio.Application.12 That tells you the DEFAULT version that is installed (might be others)

HKEY_CLASSES_ROOT\Visio.Application.12 Sub Key CLSID will give you a guid: {00021A20-0000-0000-C000-000000000046}

HKEY_CLASSES_ROOT\CLSID{00021A20-0000-0000-C000-000000000046} in turn will give you Sub Key "LocalServer32" Which will contain the path to the EXE.

C:\PROGRA~1\MICROS~4\Office12\VISIO.EXE /Automation

As you can see, in my case it has the short path form.

Roger Willcocks
+1  A: 

Here is my solution, based on Roger's answer:

    RegistryKey regVersionString = Registry.ClassesRoot.OpenSubKey("Visio.Drawing\\CurVer");
    Console.WriteLine("VERSION: " + regVersionString.GetValue(""));

    RegistryKey regClassId = Registry.ClassesRoot.OpenSubKey(regVersionString.GetValue("") + "\\CLSID");
    Console.WriteLine("CLSID: " + regClassId.GetValue(""));

    RegistryKey regInstallPath = Registry.ClassesRoot.OpenSubKey("CLSID\\" + regClassId.GetValue("") + "\\LocalServer32");
    Console.WriteLine("PATH: " + regInstallPath.GetValue(""));
brass-kazoo