2014-04-02 62 views
0

你好我正在搜索的是在系统中安装的Outlook吗?我在Java工作。我找到了一些链接,但我不能达到我的目标。我发现一种方法 “类型officeType = Type.GetTypeFromProgID(”Outlook.Application“);”,但我不知道我应该导入哪个包。 我写下面的代码,但它给了我错误。如何检查outlook是否在系统中安装或不使用java?

Type officeType = Type.GetTypeFromProgID("Outlook.Application"); 

if (officeType == null) 
{ 
    // Outlook is not installed. 
    // Show message or alert that Outlook is not installed. 
} 
else 
{ 
    // Outlook is installed.  
    // Continue your work. 
} 

有助于解决此问题。在此先感谢...

+0

谷歌搜索“GetTypeFromProgID”的第一个结果是http://msdn.microsoft.com/en-us/library/vstudio/system.type.gettypefromprogid。在java中使用* that *方法会遇到一些麻烦。 –

+0

@OlegEstekhin是否有可能使用java? –

回答

2

每个软件在安装过程中创建一个条目到Windows注册表中。为了找出是否安装了任何软件,您需要在Windows机器上扫描和搜索注册表。您可以使用第三方Java API访问Windows注册表:jRegistryKey

样例程序:

package your.pkg; 

import java.io.File; 
import java.util.Iterator; 

import ca.beq.util.win32.registry.RegistryKey; 
import ca.beq.util.win32.registry.RootKey; 

public class Test { 

    public static void main(String... args) throws Exception { 
     RegistryKey.initialize(Test.class.getResource("jRegistryKey.dll").getFile()); 
     RegistryKey key = new RegistryKey(RootKey.HKLM, "Software\\Microsoft\\Office\\<version>\\Outlook\\"); 
     for (Iterator<RegistryKey> subkeys = key.subkeys(); subkeys.hasNext();) { 
      RegistryKey subkey = subkeys.next(); 
      System.out.println(subkey.getName()); // You need to check here if there's anything which matches "Mozilla FireFox". 
     } 
    } 
} 

希望这有助于你。

+0

我正在使用Ubuntu操作系统..是否有可能? –

+1

不知道如何在Ubuntu上做到这一点。将很快找出并更新答案。 –

+0

我应该从http://sourceforge.net/projects/jregistrykey/postdownload?source=dlp下载吗? –

相关问题