当独立服务器以管理员权限启动时客户端转换失败

Client conversion fails when Standalone Server started with Administrator permissions

我正在 Windows 10 上使用阴影罐测试使用 Documents4j 的各种方法。 我使用以下内容:

SERVER: documents4j-server-standalone-1.1.5-shaded.jar
Command Line: java -jar %~dp0documents4j-server-standalone-1.1.5-shaded.jar http://localhost:9998 -L%~dp0server-log.log -Vall 

CLIENT: documents4j-client-standalone-1.1.5-shaded.jar
Command Line: java -jar %~dp0documents4j-client-standalone-1.1.5-shaded.jar http://localhost:9998 -L%~dp0client-log.log -Vall

在客户端控制台中,我输入 0 和完整的文件路径,即 C:\temp2\Sample.docx

这条消息然后displayed:Scheduled转换:C:\temp2\Sample.docx -> C:\temp2\Sample.docx.txt

当独立服务器以登录用户身份启动时转换成功,但当以管理员权限启动时失败(未生成转换文件)。

以下是日志摘录(附后):

客户端日志

Line 2220

FAILED [ADMINISTRATOR]
2021-04-03 13:39:02,731 WARN  [main] c.documents4j.standalone.StandaloneClient - Converter com.documents4j.job.RemoteConverter@475b7792 is not operational

SUCCESSFUL [USER]
2021-04-03 13:54:49,694 INFO  [main] c.documents4j.standalone.StandaloneClient - Converter com.documents4j.job.RemoteConverter@160c3ec1 is operational

服务器日志

LIne 303
FAILED [ADMINISTRATOR]
2021-04-03 13:39:01,862 TRACE [grizzly-http-server-0] c.d.c.msoffice.MicrosoftWordBridge - Execute no-argument script C:\Users\GRAEME~1.PTB\AppData\Local\Temp17419299961-0\word_assert1520023368.vbs
2021-04-03 13:39:01,862 DEBUG [grizzly-http-server-0] org.zeroturnaround.exec.ProcessExecutor - Executing [cmd, /S, /C, ""C:\Users\GRAEME~1.PTB\AppData\Local\Temp17419299961-0\word_assert1520023368.vbs""] in C:\Users\GRAEME~1.PTB\AppData\Local\Temp17419299961-0.
2021-04-03 13:39:01,872 DEBUG [grizzly-http-server-0] org.zeroturnaround.exec.ProcessExecutor - Started Process[pid=18600, exitValue="not exited"]
2021-04-03 13:39:01,873 TRACE [Thread-4] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@4e48de90 started.
2021-04-03 13:39:01,873 TRACE [Thread-5] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@786a36ca started.
2021-04-03 13:39:02,150 TRACE [Thread-4] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@4e48de90 finished.
2021-04-03 13:39:02,150 TRACE [Thread-5] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@786a36ca finished.
2021-04-03 13:39:02,153 DEBUG [WaitForProcess-Process[pid=18600, exitValue="not exited"]] org.zeroturnaround.exec.WaitForProcess - Process[pid=18600, exitValue=-6] stopped with exit code -6

SUCCESSFUL [USER]
2021-04-03 13:54:48,260 TRACE [grizzly-http-server-1] c.d.c.msoffice.MicrosoftWordBridge - Execute no-argument script C:\Users\GRAEME~1.PTB\AppData\Local\Temp17420258290-0\word_assert59744299.vbs
2021-04-03 13:54:48,261 DEBUG [grizzly-http-server-1] org.zeroturnaround.exec.ProcessExecutor - Executing [cmd, /S, /C, ""C:\Users\GRAEME~1.PTB\AppData\Local\Temp17420258290-0\word_assert59744299.vbs""] in C:\Users\GRAEME~1.PTB\AppData\Local\Temp17420258290-0.
2021-04-03 13:54:48,317 DEBUG [grizzly-http-server-1] org.zeroturnaround.exec.ProcessExecutor - Started Process[pid=1724, exitValue="not exited"]
2021-04-03 13:54:48,318 TRACE [Thread-5] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@11cbcb1c started.
2021-04-03 13:54:48,318 TRACE [Thread-4] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@2c99b36 started.
2021-04-03 13:54:48,750 TRACE [Thread-4] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@2c99b36 finished.
2021-04-03 13:54:48,750 TRACE [Thread-5] o.zeroturnaround.exec.stream.StreamPumper - org.zeroturnaround.exec.stream.StreamPumper@11cbcb1c finished.
2021-04-03 13:54:48,753 DEBUG [WaitForProcess-Process[pid=1724, exitValue="not exited"]] org.zeroturnaround.exec.WaitForProcess - Process[pid=1724, exitValue=3] stopped with exit code 3

此外,启动独立客户端时会出现这些警告:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/C:/documents4j/documents4j-server-standalone-1.1.5-shaded.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

documents4j documentation 中所指出的,您可能需要准备通常未设置为 运行 Word 的用户。正如文档中所说:

  1. 在 32 位系统上,创建文件夹 C:\Windows\System32\config\systemprofile\Desktop。在 64 位系统上,创建文件夹 C:\Windows\SysWOW64\config\systemprofile\Desktop。可以在 MSDN 上找到更多信息。
  2. 您可以操纵 MS Window 的注册表,使 MS Office 应用程序 运行 使用本地服务帐户以外的其他帐户。这种方法记录在 MSDN 上。请注意,这会破坏 MS Window 的沙箱模型,并对 运行 MS Office 的计算机造成额外的安全威胁。

谢谢 Rafael - 现已解决! 我回顾了这些信息,现在我明白发生了什么。要 运行 成功 Word/Excel 需要一个有效的用户配置文件 - 在我的例子中,它是安装 Word/Excel 的配置文件。 Word/Excel 需要权限才能将临时文件写入 %USERPROFILE%\Local\Temp。当程序以管理员身份 运行 时,系统似乎试图写入不存在的位置,或者系统没有对原始 %USERPROFILE%\Local\Temp.

的权限

除了 documents4j 文档之外,还需要一个额外的步骤。

Céderic Missinne 于 2018 年 10 月 10 日就此主题在较早的 post 中概述了这一点: Automating MS Word in Server 2012 R2

Start - Run - mmc comexp.msc /32
Expand: Component Services –> Computers – My Computer – DCOM Config
Search for: Microsoft Word 97 –> 2003 Document
RMC – Properties – Go to tab: Identity Set from “The launching user” to “This user”.
Use a “local Administrator account” which has once signed in to the server machine and 
has opened Word at least once in an interactive desktop.

在我的例子中,我从 'The interactive user' 更改为 'The launching user'。

当 运行 作为管理员时,StandaloneServer 成功运行。

这也解决了一个类似的问题,我使用 Apache Proc运行!

将 StandaloneServer 运行ning 作为 Windows 服务

再次感谢拉斐尔!