How do I programatically check if Visio is installed, and where?

12,981

Solution 1

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.

Solution 2

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(""));

Solution 3

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.

Share:
12,981
brasskazoo
Author by

brasskazoo

I am a Software and Cloud Solutions Engineer with a passion for building quality and automation into the development, testing and deployment lifecycles. Currently working with a large AWS hybrid-cloud integration project, including VPC architecting and solution design, serverless applications and shifting applications to EC2. Primarily I work with terraform, node.js, react and java, with side projects currently in react-native and GraphQL for cross-platform mobile applications. Agile, DevOps culture, Code Quality and Continuous Integration are cornerstones of my development efforts.

Updated on June 04, 2022

Comments

  • brasskazoo
    brasskazoo almost 2 years

    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...

  • brasskazoo
    brasskazoo almost 15 years
    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)..
  • marcc
    marcc almost 15 years
    On my computer, the default value for the key is a REG_SZ with the value "Visio.Drawing.11"
  • brasskazoo
    brasskazoo almost 15 years
    Just got to that :) - HKLM\SOFTWARE\Classes\Visio.Drawing.11\protocol\server leads me to a visio.exe path!