rundll32 url.dll,FileProtocolHandler

筅森魡賤 提交于 2019-11-29 23:12:49

问题


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).


回答1:


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" );
  }


来源:https://stackoverflow.com/questions/13047158/rundll32-url-dll-fileprotocolhandler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!