如何使用c#
以编程方式检查OpenOffice是否已安装答案 0 :(得分:2)
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;
}
}
答案 1 :(得分:0)
与其他语言相同吗?搜索文件系统上的已知位置以查找启动开放式办公室的可执行文件?检查图书馆?解析“哪个openoffice”的输出?
有很多选择,我会说大多数都不可靠。
答案 2 :(得分:0)
这是一个解决方案,它获取默认程序的启动位置以打开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