rundll32 url.dll,FileProtocolHandler

Nanocom picture Nanocom · Oct 24, 2012 · Viewed 13.9k times · Source

I'm using rundll32 url.dll,FileProtocolHandler my_file.dotx to open files under Windows.

It works fine with .docx documents, but when I try it with .dotx documents (template documents), it creates a new .docx based on the template.

Just as the normal behavior in the windows explorer : when you double-click on a .dotx template file, it creates a new .docx file based on it. If you want to open the real .dotx file, you have to right-click on it and select "open" instead of "new".

Question is: how to do the same with rundll32? Is there an option in the command to force the opening of the underlying template instead of creating a new document?

Edit: I need a way to do it without C functions, just plain text, in the command line (I'm using Java to do it).

Answer

Preet Sangha picture Preet Sangha · Oct 24, 2012

Maybe you can wrap a simple C program around ShellExecute, passing the verb OPEN.

ShellExecute(NULL, TEXT("open"), 
TEXT("rundll32.exe"), TEXT("url.dll,FileProtocolHandler pathToGadget"), 
NULL, SW_SHOWNORMAL);   

I found this example here.

edit:

Since you're doing this in Java - you could try a JNI wrapping of the ShellExceute function like this (from the example I found on The Wannabe Java Rockstar and butchered)

 public static boolean execute(String file, String parameters) {
    Function shellExecute =
      Shell32.getInstance().getFunction(SHELL_EXECUTE.toString());
    Int32 ret = new Int32();
    shellExecute.invoke(ret, // return value
                        new Parameter[] {
                          new Handle(),         // hWnd
                          new Str("open"),      // lpOperation
                          new Str(file),        // lpFile
                          new Str(parameters),  // lpParameters
                          new Str(),            // lpDirectory
                          new Int32(1)          // nShowCmd
                        });
    if(ret.getValue() <= 32) {
        System.err.println("could not execute ShellExecute: " +
                           file + ". Return: " + ret.getValue());
    }
    return (ret.getValue() > 32);
  }

  public static void main(String[] args) {
    ShellExecute.execute("rundll32.exe","url.dll,FileProtocolHandler pathToGadget" );
  }