tags:

views:

268

answers:

3

I want to invoke outlook from the command line (for various reasons) and wanted to know how I go about discovering the Path to the Outlook.exe file.

I'm pretty sure it's stored in the registry, but was wondering how to go about reading that from Java.

thanks

A: 

I found a Microsoft page that describes the procedure, just not in Java.

So I guess the question becomes how do I access the registry from java.

Allain Lalonde
I suggest editing both your question and title, or starting a new question if the nature of your question has changed.
Simucal
+1  A: 

I found this site that might be able to help you. It's a Java Registry wrapper, seems to have a lot of features but no idea how robust the implementation is.

Otis
A: 

Using Otis' answer the following code does it nicely.

static String getOutlookPath() {
  // Message message = new Message();
  final String classID;
  final String outlookPath;

  { // Fetch the Outlook Class ID
    int[] ret = RegUtil.RegOpenKey(RegUtil.HKEY_LOCAL_MACHINE,   "SOFTWARE\\Classes\\Outlook.Application\\CLSID", RegUtil.KEY_QUERY_VALUE);
    int handle = ret[RegUtil.NATIVE_HANDLE];
    byte[] outlookClassID = RegUtil.RegQueryValueEx(handle, "");

    classID = new String(outlookClassID).trim(); // zero terminated bytes
    RegUtil.RegCloseKey(handle);
  }

  { // Using the class ID from above pull up the path
    int[] ret = RegUtil.RegOpenKey(RegUtil.HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes\\CLSID\\" + classID + "\\LocalServer32", RegUtil.KEY_QUERY_VALUE);
    int handle = ret[RegUtil.NATIVE_HANDLE];
    byte[] pathBytes = RegUtil.RegQueryValueEx(handle, "");

    outlookPath = new String(pathBytes).trim(); // zero terminated bytes
    RegUtil.RegCloseKey(handle);
  }

  return outlookPath;
}
Allain Lalonde