【发布时间】:2010-10-21 06:23:46
【问题描述】:
如何检查 OpenOffice 是否使用 c# 以编程方式安装
【问题讨论】:
-
哪个操作系统? Windows、Linux 还是其他?
标签: c# openoffice.org
如何检查 OpenOffice 是否使用 c# 以编程方式安装
【问题讨论】:
标签: c# openoffice.org
public bool isOpenofficeInstalled()
{
//The registry key:
string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey))
{
bool flag = false;
//Let's go through the registry keys and get the info we need:
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
try
{
//If the key has value, continue, if not, skip it:
// if (((sk.GetValue("DisplayName")).ToString() == "OpenOffice.org 3.2"))
if((sk.GetValue("DisplayName")).ToString() == "OpenOffice.org 3.2")
{
flag = true;
////install location ?
//if (sk.GetValue("InstallLocation") == null)
// Software += sk.GetValue("DisplayName") + " - Install path not known\n"; //Nope, not here.
//else
// Software += sk.GetValue("DisplayName") + " - " + sk.GetValue("InstallLocation") + "\n"; //Yes, here it is...
}
}
catch (Exception)
{
}
}
}
return flag;
}
}
【讨论】:
public bool IsOpenOfficeInstalled(){ 之前放置 4 个空格,使其成为代码的一部分。
这里是获取默认程序的启动位置以打开odt文件的解决方案。只要文件关联没有改变,无论安装什么版本,它都可以工作。
(这是 VB.NET)
Dim odt = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(".odt")
Dim linkedValue = odt.GetValue("")
Dim linkedKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(linkedValue)
Dim openWith = linkedKey.OpenSubKey("Shell\Open\Command").GetValue("")
Dim O As String = CStr(openWith)
If O.Contains("swriter.exe") Then
// proceed with code
Else
// error message
End If
【讨论】:
和其他语言一样吗?在文件系统上的已知位置搜索启动 open office 的可执行文件?检查图书馆?解析“which openoffice”的输出?
有很多选择,我想说其中大多数都不可靠。
【讨论】: