rundll32 url.dll,FileProtocolHandler

Nan*_*com 4 java windows command-line ms-word rundll32

我用来rundll32 url.dll,FileProtocolHandler my_file.dotx在 Windows 下打开文件。

它适用于 .docx 文档,但当我尝试使用 .dotx 文档(模板文档)时,它会根据模板创建一个新的 .docx。

就像 Windows 资源管理器中的正常行为一样:当您双击 .dotx 模板文件时,它会基于它创建一个新的 .docx 文件。如果你想打开真正的.dotx文件,你必须右键单击它并选择“打开”而不是“新建”。

问题是:如何对 rundll32 执行同样的操作?命令中是否有一个选项可以强制打开底层模板而不是创建新文档?

编辑:我需要一种方法来做到这一点,无需C函数,只需纯文本,在命令行中(我使用Java来做到这一点)。

Pre*_*gha 5

也许您可以将一个简单的 C 程序封装在ShellExecute周围,并传递动词 OPEN。

ShellExecute(NULL, TEXT("open"), 
TEXT("rundll32.exe"), TEXT("url.dll,FileProtocolHandler pathToGadget"), 
NULL, SW_SHOWNORMAL);   
Run Code Online (Sandbox Code Playgroud)

我在这里找到了这个例子。

编辑:

由于您是在 Java 中执行此操作 - 您可以尝试像这样对 ShellExceute 函数进行 JNI 包装(来自我在 The Wannabe Java Rockstar 上找到并被屠宰的示例)

 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" );
  }
Run Code Online (Sandbox Code Playgroud)