您好,我正在搜索系统中是否安装了 Outlook?我正在用Java工作。我发现了一些链接,但我无法达到我的目标。我找到了一种方法 “键入 officeType = Type.GetTypeFromProgID("Outlook.Application");”,但我不知道应该导入哪个包。 我编写了以下代码,但它给了我错误。
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.
}
帮忙解决这个问题。提前致谢...
最佳答案
每个软件在安装过程中都会在 Windows 注册表中创建一个条目。为了查明是否安装了任何软件,您需要扫描并搜索 Windows 计算机中的注册表。您可以使用第 3 方 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".
}
}
}
希望这对您有帮助。
关于java - 如何使用java检查系统中是否安装了outlook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22804519/