如何以编程方式检查是否已安装Visio,以及在哪里?

时间:2021-08-02 20:32:40

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

我正在构建一个C#应用程序,用于导出要与Visio组织结构图向导一起使用的CSV文件。

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

如何检查Visio的安装是否存在,以及路径是什么?

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

最明显的方法是检查C:\ Program Files \ Office12 \ ORGWIZ.EXE是否存在,但这完全取决于安装了Visio 2007 ..

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

我的另一个想法是检查注册表,但最可靠的来源是什么?我查看了HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Office \,其中有版本号,但在它们下面是一个Visio \ InstallRoot,除了检查每个版本外,这将是完美的..

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

我在别处读到我可以在Software \ Microsoft \ Windows \ CurrentVersion \ Uninstall \下查看卸载信息,但对于Windows组件来说这看起来相当复杂......

3 个解决方案

#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。如果它不存在,则不安装。如果确实存在,CurVer子键将为您提供类似Visio.Application.12的内容,它会告诉您已安装的DEFAULT版本(可能是其他版本)

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

HKEY_CLASSES_ROOT \ Visio.Application.12子密钥CLSID将为您提供指导:{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.

HKEY_CLASSES_ROOT \ CLSID {00021A20-0000-0000-C000-000000000046}依次为您提供子键“LocalServer32”,其中包含EXE的路径。

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

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

如您所见,在我的情况下,它具有短路径形式。

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

#3


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

你能检查Visio文件扩展名是否已注册,以及是什么应用程序?

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.

查看HKEY_CLASSES_ROOT \\。vsd,密钥是否存在,值是什么?将它们与一组指示应用程序已安装的值进行比较。

#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。如果它不存在,则不安装。如果确实存在,CurVer子键将为您提供类似Visio.Application.12的内容,它会告诉您已安装的DEFAULT版本(可能是其他版本)

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

HKEY_CLASSES_ROOT \ Visio.Application.12子密钥CLSID将为您提供指导:{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.

HKEY_CLASSES_ROOT \ CLSID {00021A20-0000-0000-C000-000000000046}依次为您提供子键“LocalServer32”,其中包含EXE的路径。

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

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

如您所见,在我的情况下,它具有短路径形式。

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

#3


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

你能检查Visio文件扩展名是否已注册,以及是什么应用程序?

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.

查看HKEY_CLASSES_ROOT \\。vsd,密钥是否存在,值是什么?将它们与一组指示应用程序已安装的值进行比较。